small changes

This commit is contained in:
ModProg 2021-09-27 01:29:10 +02:00
parent f002cdcc99
commit 76f7211d8b
6 changed files with 10 additions and 17 deletions

View file

@ -15,7 +15,7 @@ enum ArgChoice {
#[clap(alias = "b", alias = "z")] #[clap(alias = "b", alias = "z")]
Baz, Baz,
// Hiding variants from help and completion is supported // Hiding variants from help and completion is supported
#[clap(hidden)] #[clap(hidden = true)]
Hidden, Hidden,
} }

View file

@ -308,8 +308,6 @@ impl Attrs {
self.push_method(ident, self.name.clone().translate(*self.env_casing)); self.push_method(ident, self.name.clone().translate(*self.env_casing));
} }
Hidden(ident) => self.push_method(ident, true),
ArgEnum(_) => self.is_enum = true, ArgEnum(_) => self.is_enum = true,
FromGlobal(ident) => { FromGlobal(ident) => {

View file

@ -102,10 +102,7 @@ fn lits(
} }
fn gen_variants(lits: &[(TokenStream, Ident)]) -> TokenStream { fn gen_variants(lits: &[(TokenStream, Ident)]) -> TokenStream {
let lit = lits let lit = lits.iter().map(|l| &l.0).collect::<Vec<_>>();
.iter()
.map(|(arg_value, ..)| arg_value)
.collect::<Vec<_>>();
quote! { quote! {
fn variants() -> Vec<clap::ArgValue<'static>> { fn variants() -> Vec<clap::ArgValue<'static>> {

View file

@ -76,11 +76,13 @@ pub fn args(name: &Ident) {
pub fn arg_enum(name: &Ident) { pub fn arg_enum(name: &Ident) {
append_dummy(quote! { append_dummy(quote! {
impl clap::ArgEnum for #name { impl clap::ArgEnum for #name {
const VARIANTS: &'static [clap::ArgValue<'static>] = &[]; fn variants() -> Vec<clap::ArgValue<'static>> {
unimplemented!()
}
fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> { fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> {
unimplemented!() unimplemented!()
} }
fn as_arg(&self) -> Option<&'static str> { fn as_arg(&self) -> Option<clap::ArgValue<'static>> {
unimplemented!() unimplemented!()
} }
} }

View file

@ -21,7 +21,6 @@ pub enum ClapAttr {
Subcommand(Ident), Subcommand(Ident),
VerbatimDocComment(Ident), VerbatimDocComment(Ident),
ExternalSubcommand(Ident), ExternalSubcommand(Ident),
Hidden(Ident),
// ident [= "string literal"] // ident [= "string literal"]
About(Ident, Option<LitStr>), About(Ident, Option<LitStr>),
@ -173,7 +172,6 @@ impl Parse for ClapAttr {
"subcommand" => Ok(Subcommand(name)), "subcommand" => Ok(Subcommand(name)),
"external_subcommand" => Ok(ExternalSubcommand(name)), "external_subcommand" => Ok(ExternalSubcommand(name)),
"verbatim_doc_comment" => Ok(VerbatimDocComment(name)), "verbatim_doc_comment" => Ok(VerbatimDocComment(name)),
"hidden" => Ok(Hidden(name)),
"default_value" => { "default_value" => {
abort!(name, abort!(name,

View file

@ -99,12 +99,10 @@ impl<'help> ArgValue<'help> {
/// [hidden]: ArgValue::hidden /// [hidden]: ArgValue::hidden
/// [possible value]: crate::Arg::possible_values /// [possible value]: crate::Arg::possible_values
/// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values() /// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values()
pub const fn new(name: &'help str) -> Self { pub fn new(name: &'help str) -> Self {
ArgValue { ArgValue {
name, name,
about: None, ..Default::default()
hidden: false,
aliases: Vec::new(),
} }
} }
@ -120,7 +118,7 @@ impl<'help> ArgValue<'help> {
/// # ; /// # ;
/// ``` /// ```
#[inline] #[inline]
pub const fn about(mut self, about: &'help str) -> Self { pub fn about(mut self, about: &'help str) -> Self {
self.about = Some(about); self.about = Some(about);
self self
} }
@ -140,7 +138,7 @@ impl<'help> ArgValue<'help> {
/// ``` /// ```
/// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values() /// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values()
#[inline] #[inline]
pub const fn hidden(mut self, yes: bool) -> Self { pub fn hidden(mut self, yes: bool) -> Self {
self.hidden = yes; self.hidden = yes;
self self
} }