Skip to content

Commit

Permalink
Merge pull request #100 from rsteube/support-hidden
Browse files Browse the repository at this point in the history
support hidden
  • Loading branch information
rsteube authored Jul 17, 2023
2 parents d903df3 + 7446092 commit 7a72bd8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/carapace_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ use clap_complete::*;
use indexmap::IndexMap as Map;
use serde::Serialize;

fn default<T: Default + PartialEq>(t: &T) -> bool {
*t == Default::default()
}

#[derive(Default, Serialize)]
pub struct Command {
pub name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<String>,
pub description: String,
#[serde(skip_serializing_if = "default")]
pub hidden: bool,
#[serde(skip_serializing_if = "Map::is_empty")]
pub flags: Map<String, String>,
#[serde(skip_serializing_if = "Map::is_empty")]
Expand Down Expand Up @@ -66,6 +72,7 @@ fn command_for(cmd: &clap::Command, root: bool) -> Command {
name: cmd.get_name().to_owned(),
aliases: cmd.get_all_aliases().map(String::from).collect(),
description: cmd.get_about().unwrap_or_default().to_string(),
hidden: cmd.is_hide_set(),
flags: flags_for(cmd, false),
persistentflags: if let true = root {
flags_for(cmd, true)
Expand Down Expand Up @@ -200,6 +207,14 @@ fn modifier_for(option: &Arg) -> String {
let mut modifier = vec![];

if option.get_action().takes_values() {
if option.is_hide_set() {
modifier.push("&")
}

if option.is_required_set() {
modifier.push("!")
}

if option.is_require_equals_set() {
modifier.push("?");
} else {
Expand Down

0 comments on commit 7a72bd8

Please sign in to comment.