mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
aliases
This commit is contained in:
@@ -98,12 +98,16 @@ fn build_app(name: LitStr, opt: &mut Options, params: &mut [ParamType]) -> Token
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let required = LitBool::new(subcommand_required, Span::call_site());
|
||||
let alias = &opt.common().aliases;
|
||||
quote! {
|
||||
pub fn build_app() -> rpc_toolkit_prelude::App<'static, 'static> {
|
||||
let mut app = rpc_toolkit_prelude::App::new(#name);
|
||||
#(
|
||||
app = app.about(#about);
|
||||
)*
|
||||
#(
|
||||
app = app.alias(#alias);
|
||||
)*
|
||||
#(
|
||||
app = app.arg(#arg);
|
||||
)*
|
||||
|
||||
@@ -19,6 +19,7 @@ impl Default for ExecutionContext {
|
||||
pub struct LeafOptions {
|
||||
blocking: Option<Path>,
|
||||
is_async: bool,
|
||||
aliases: Vec<LitStr>,
|
||||
about: Option<LitStr>,
|
||||
rename: Option<Ident>,
|
||||
exec_ctx: ExecutionContext,
|
||||
|
||||
@@ -126,6 +126,30 @@ pub fn parse_command_attr(args: AttributeArgs) -> Result<Options> {
|
||||
"`display` cannot be assigned to",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::List(list)) if list.path.is_ident("aliases") => {
|
||||
if !opt.common().aliases.is_empty() {
|
||||
return Err(Error::new(list.span(), "duplicate argument `alias`"));
|
||||
}
|
||||
for nested in list.nested {
|
||||
match nested {
|
||||
NestedMeta::Lit(Lit::Str(alias)) => opt.common().aliases.push(alias),
|
||||
a => return Err(Error::new(a.span(), "`alias` must be a string")),
|
||||
}
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("alias") => {
|
||||
return Err(Error::new(p.span(), "`alias` requires an argument"));
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("alias") => {
|
||||
if !opt.common().aliases.is_empty() {
|
||||
return Err(Error::new(nv.path.span(), "duplicate argument `alias`"));
|
||||
}
|
||||
if let Lit::Str(alias) = nv.lit {
|
||||
opt.common().aliases.push(alias);
|
||||
} else {
|
||||
return Err(Error::new(nv.lit.span(), "`alias` must be a string"));
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("cli_only") => {
|
||||
match &opt.common().exec_ctx {
|
||||
ExecutionContext::Standard => {
|
||||
|
||||
@@ -10,6 +10,8 @@ pub fn command(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
|
||||
/// `#[arg(...)]` -> Take this argument as a parameter
|
||||
/// - `#[arg(help = "Help text")]` -> Set help text for the arg
|
||||
/// - `#[arg(alias = "ls")]` -> Set the alias `ls` in the CLI
|
||||
/// - `#[arg(aliases("show", "ls"))]` -> Set the aliases `ls` and `show` in the CLI
|
||||
/// - `#[arg(rename = "new_name")]` -> Set the name of the arg to `new_name` in the RPC and CLI
|
||||
/// - `#[arg(short = "a")]` -> Set the "short" representation of the arg to `-a` on the CLI
|
||||
/// - `#[arg(long = "arg")]` -> Set the "long" representation of the arg to `--arg` on the CLI
|
||||
|
||||
Reference in New Issue
Block a user