mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
Use full span information whenever possible
This commit is contained in:
parent
9a15e47af0
commit
3f314ce39e
8 changed files with 30 additions and 31 deletions
|
@ -118,7 +118,7 @@ impl Method {
|
|||
None => match env::var(env_var) {
|
||||
Ok(val) => syn::LitStr::new(&val, ident.span()),
|
||||
Err(_) => {
|
||||
abort!(ident.span(),
|
||||
abort!(ident,
|
||||
"cannot derive `{}` from Cargo.toml", ident;
|
||||
note = "`{}` environment variable is not set", env_var;
|
||||
help = "use `{} = \"...\"` to set {} manually", ident, ident;
|
||||
|
@ -186,7 +186,7 @@ impl Parser {
|
|||
|
||||
Some(func) => match func {
|
||||
syn::Expr::Path(_) => quote!(#func),
|
||||
_ => abort!(func.span(), "`parse` argument must be a function path"),
|
||||
_ => abort!(func, "`parse` argument must be a function path"),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -210,7 +210,7 @@ impl CasingStyle {
|
|||
"screamingsnake" | "screamingsnakecase" => cs(ScreamingSnake),
|
||||
"snake" | "snakecase" => cs(Snake),
|
||||
"verbatim" | "verbatimcase" => cs(Verbatim),
|
||||
s => abort!(name.span(), "unsupported casing: `{}`", s),
|
||||
s => abort!(name, "unsupported casing: `{}`", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ impl Attrs {
|
|||
ty
|
||||
} else {
|
||||
abort!(
|
||||
ident.span(),
|
||||
ident,
|
||||
"#[clap(default_value)] (without an argument) can be used \
|
||||
only on field level";
|
||||
|
||||
|
@ -468,13 +468,13 @@ impl Attrs {
|
|||
match *ty {
|
||||
Ty::OptionOption => {
|
||||
abort!(
|
||||
ty.span(),
|
||||
field.ty,
|
||||
"Option<Option<T>> type is not allowed for subcommand"
|
||||
);
|
||||
}
|
||||
Ty::OptionVec => {
|
||||
abort!(
|
||||
ty.span(),
|
||||
field.ty,
|
||||
"Option<Vec<T>> type is not allowed for subcommand"
|
||||
);
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ impl Attrs {
|
|||
match *ty {
|
||||
Ty::Bool => {
|
||||
if res.is_positional() && !res.has_custom_parser {
|
||||
abort!(ty.span(),
|
||||
abort!(field.ty,
|
||||
"`bool` cannot be used as positional parameter with default parser";
|
||||
help = "if you want to create a flag add `long` or `short`";
|
||||
help = "If you really want a boolean parameter \
|
||||
|
@ -512,24 +512,24 @@ impl Attrs {
|
|||
)
|
||||
}
|
||||
if let Some(m) = res.find_method("default_value") {
|
||||
abort!(m.name.span(), "default_value is meaningless for bool")
|
||||
abort!(m.name, "default_value is meaningless for bool")
|
||||
}
|
||||
if let Some(m) = res.find_method("required") {
|
||||
abort!(m.name.span(), "required is meaningless for bool")
|
||||
abort!(m.name, "required is meaningless for bool")
|
||||
}
|
||||
}
|
||||
Ty::Option => {
|
||||
if let Some(m) = res.find_method("default_value") {
|
||||
abort!(m.name.span(), "default_value is meaningless for Option")
|
||||
abort!(m.name, "default_value is meaningless for Option")
|
||||
}
|
||||
if let Some(m) = res.find_method("required") {
|
||||
abort!(m.name.span(), "required is meaningless for Option")
|
||||
abort!(m.name, "required is meaningless for Option")
|
||||
}
|
||||
}
|
||||
Ty::OptionOption => {
|
||||
if res.is_positional() {
|
||||
abort!(
|
||||
ty.span(),
|
||||
field.ty,
|
||||
"Option<Option<T>> type is meaningless for positional argument"
|
||||
)
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ impl Attrs {
|
|||
Ty::OptionVec => {
|
||||
if res.is_positional() {
|
||||
abort!(
|
||||
ty.span(),
|
||||
field.ty,
|
||||
"Option<Vec<T>> type is meaningless for positional argument"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use syn::{
|
|||
self, parenthesized,
|
||||
parse::{Parse, ParseBuffer, ParseStream},
|
||||
punctuated::Punctuated,
|
||||
spanned::Spanned,
|
||||
Attribute, Expr, ExprLit, Ident, Lit, LitBool, LitStr, Token,
|
||||
};
|
||||
|
||||
|
@ -62,7 +61,7 @@ impl Parse for ClapAttr {
|
|||
let check_empty_lit = |s| {
|
||||
if lit_str.is_empty() {
|
||||
abort!(
|
||||
lit.span(),
|
||||
lit,
|
||||
"`#[clap({} = \"\")` is deprecated, \
|
||||
now it's default behavior",
|
||||
s
|
||||
|
@ -112,7 +111,7 @@ impl Parse for ClapAttr {
|
|||
}
|
||||
|
||||
Err(_) => abort! {
|
||||
assign_token.span(),
|
||||
assign_token,
|
||||
"expected `string literal` or `expression` after `=`"
|
||||
},
|
||||
}
|
||||
|
@ -130,7 +129,7 @@ impl Parse for ClapAttr {
|
|||
if parser_specs.len() == 1 {
|
||||
Ok(Parse(name, parser_specs[0].clone()))
|
||||
} else {
|
||||
abort!(name.span(), "parse must have exactly one argument")
|
||||
abort!(name, "parse must have exactly one argument")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +144,7 @@ impl Parse for ClapAttr {
|
|||
}
|
||||
|
||||
Err(_) => {
|
||||
abort!(name.span(),
|
||||
abort!(name,
|
||||
"`#[clap(raw(...))` attributes are removed, \
|
||||
they are replaced with raw methods";
|
||||
help = "if you meant to call `clap::Arg::raw()` method \
|
||||
|
@ -179,7 +178,7 @@ impl Parse for ClapAttr {
|
|||
|
||||
"skip" => Ok(Skip(name, None)),
|
||||
|
||||
_ => abort!(name.span(), "unexpected attribute: {}", name_str),
|
||||
_ => abort!(name, "unexpected attribute: {}", name_str),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ fn gen_augment_subcommands(
|
|||
}
|
||||
}
|
||||
_ => abort!(
|
||||
variant.span(),
|
||||
variant,
|
||||
"`flatten` is usable only with single-typed tuple variants"
|
||||
),
|
||||
},
|
||||
|
@ -87,10 +87,9 @@ fn gen_augment_subcommands(
|
|||
}
|
||||
}
|
||||
}
|
||||
Unnamed(..) => abort!(
|
||||
variant.span(),
|
||||
"non single-typed tuple enums are not supported"
|
||||
),
|
||||
Unnamed(..) => {
|
||||
abort!(variant, "non single-typed tuple enums are not supported")
|
||||
}
|
||||
};
|
||||
|
||||
let name = attrs.cased_name();
|
||||
|
@ -175,7 +174,7 @@ fn gen_from_subcommand(
|
|||
}
|
||||
}
|
||||
_ => abort!(
|
||||
variant.span(),
|
||||
variant,
|
||||
"`flatten` is usable only with single-typed tuple variants"
|
||||
),
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
error: `flatten` is usable only with single-typed tuple variants
|
||||
--> $DIR/enum_flatten.rs:14:5
|
||||
|
|
||||
14 | #[clap(flatten)]
|
||||
| ^
|
||||
14 | / #[clap(flatten)]
|
||||
15 | | Variant1,
|
||||
| |____________^
|
||||
|
|
|
@ -2,4 +2,4 @@ error: Option<Option<T>> type is meaningless for positional argument
|
|||
--> $DIR/opt_opt_nonpositional.rs:14:8
|
||||
|
|
||||
14 | n: Option<Option<u32>>,
|
||||
| ^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -2,4 +2,4 @@ error: Option<Vec<T>> type is meaningless for positional argument
|
|||
--> $DIR/opt_vec_nonpositional.rs:14:8
|
||||
|
|
||||
14 | n: Option<Vec<u32>>,
|
||||
| ^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -2,4 +2,4 @@ error: Option<Option<T>> type is not allowed for subcommand
|
|||
--> $DIR/subcommand_opt_opt.rs:17:10
|
||||
|
|
||||
17 | cmd: Option<Option<Command>>,
|
||||
| ^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -2,4 +2,4 @@ error: Option<Vec<T>> type is not allowed for subcommand
|
|||
--> $DIR/subcommand_opt_vec.rs:17:10
|
||||
|
|
||||
17 | cmd: Option<Vec<Command>>,
|
||||
| ^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue