mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
add default
This commit is contained in:
@@ -5,6 +5,8 @@ name = "rpc-toolkit-macro-internals"
|
||||
version = "0.1.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
cli-cookies = []
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0.26"
|
||||
|
||||
@@ -225,7 +225,11 @@ fn build_app(name: LitStr, opt: &mut Options, params: &mut [ParamType]) -> Token
|
||||
modifications.extend(quote_spanned! { ty_span =>
|
||||
arg = arg.takes_value(true);
|
||||
});
|
||||
if p.path.segments.last().unwrap().ident == "Option" {
|
||||
if let Some(default) = &arg.default {
|
||||
modifications.extend(quote_spanned! { ty_span =>
|
||||
arg = arg.default_value(#default);
|
||||
});
|
||||
} else if p.path.segments.last().unwrap().ident == "Option" {
|
||||
arg.optional = true;
|
||||
modifications.extend(quote_spanned! { ty_span =>
|
||||
arg = arg.required(false);
|
||||
|
||||
@@ -81,6 +81,7 @@ pub struct ArgOptions {
|
||||
short: Option<LitStr>,
|
||||
long: Option<LitStr>,
|
||||
parse: Option<Path>,
|
||||
default: Option<LitStr>,
|
||||
count: Option<Path>,
|
||||
multiple: Option<Path>,
|
||||
stdin: Option<Path>,
|
||||
|
||||
@@ -394,6 +394,7 @@ pub fn parse_arg_attr(attr: Attribute, arg: PatType) -> Result<ArgOptions> {
|
||||
short: None,
|
||||
long: None,
|
||||
parse: None,
|
||||
default: None,
|
||||
count: None,
|
||||
multiple: None,
|
||||
stdin: None,
|
||||
@@ -627,6 +628,28 @@ pub fn parse_arg_attr(attr: Attribute, arg: PatType) -> Result<ArgOptions> {
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("long") => {
|
||||
return Err(Error::new(p.span(), "`long` must be assigned to"));
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("default") => {
|
||||
if let Lit::Str(default) = nv.lit {
|
||||
if opt.default.is_some() {
|
||||
return Err(Error::new(
|
||||
default.span(),
|
||||
"duplicate argument `default`",
|
||||
));
|
||||
}
|
||||
opt.default = Some(default);
|
||||
} else {
|
||||
return Err(Error::new(nv.lit.span(), "`default` must be a string"));
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::List(list)) if list.path.is_ident("default") => {
|
||||
return Err(Error::new(
|
||||
list.path.span(),
|
||||
"`default` does not take any arguments",
|
||||
));
|
||||
}
|
||||
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("default") => {
|
||||
return Err(Error::new(p.span(), "`default` must be assigned to"));
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::new(arg.span(), "unknown argument"));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ version = "0.1.0"
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
cli-cookies = ["rpc-toolkit-macro-internals/cli-cookies"]
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0.1"
|
||||
rpc-toolkit-macro-internals = { path = "../rpc-toolkit-macro-internals" }
|
||||
|
||||
@@ -8,11 +8,19 @@ version = "0.1.0"
|
||||
[features]
|
||||
cbor = ["serde_cbor"]
|
||||
default = ["cbor"]
|
||||
cli-cookies = ["rpc-toolkit-macro/cli-cookies"]
|
||||
|
||||
[dependencies]
|
||||
clap = "2.33.3"
|
||||
futures = "0.3.15"
|
||||
hyper = { version="0.14.5", features=["server", "http1", "http2", "tcp", "stream", "client"] }
|
||||
hyper = { version = "0.14.5", features = [
|
||||
"server",
|
||||
"http1",
|
||||
"http2",
|
||||
"tcp",
|
||||
"stream",
|
||||
"client",
|
||||
] }
|
||||
lazy_static = "1.4.0"
|
||||
reqwest = { version = "0.11.2" }
|
||||
rpc-toolkit-macro = { path = "../rpc-toolkit-macro" }
|
||||
|
||||
1
rpc-toolkit/src/cli_helpers.rs
Normal file
1
rpc-toolkit/src/cli_helpers.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -44,6 +44,8 @@ pub use {clap, hyper, reqwest, serde, serde_json, tokio, url, yajrc};
|
||||
pub use crate::context::Context;
|
||||
pub use crate::metadata::Metadata;
|
||||
|
||||
#[cfg(feature = "cli-cookies")]
|
||||
pub mod cli_helpers;
|
||||
pub mod command_helpers;
|
||||
mod context;
|
||||
mod metadata;
|
||||
|
||||
Reference in New Issue
Block a user