-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add App::name set function to use crate_name!() macro #908
Comments
It's not omiited on purpose,probably just overlooked. Until I get a chance to add this (I recently broke my finger so am typing with one hand and it's not feasible to get real work done 😞) there is a workaround (that is technically public, but its not meant to be public and is undocumented. As such it may change in the future without warning): let mut app = // load YAML like normal
app.p.meta.name = "Some Name".into();
let m = app.get_matches(); If someone would like to submit a PR with this, it'd be an easy one just adding the fn to |
Sorry about your hand. :( To make it heal faster I submitted #910. |
Implement name setter on App; fixes #908 Probably should have done that immediately before opening an issue. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kbknapp/clap-rs/910) <!-- Reviewable:end -->
What I find a bit strange here is that I need to use a dummy name in the YAML file, because otherwise clap does some strange stuff: let mut a = if let Some(name) = yaml["name"].as_str() {
App::new(name)
} else {
let yaml_hash = yaml.as_hash().unwrap();
let sc_key = yaml_hash.keys().nth(0).unwrap();
is_sc = Some(yaml_hash.get(sc_key).unwrap());
App::new(sc_key.as_str().unwrap())
}; |
Currently, you can further specify the
about
,authors
, andversion
field of anApp
through setter methods of the same, and pull in the appropriate value throughcrate_about!()
and similar macros. Onlycrate_name!()
is special, in that we can only use it when constructing a newApp
throughApp::new
.If we construct an app through
App::from_yaml
, we have no way of setting the name to the one in Cargo.toml through the macro. It would be great to be able to set the name afterApp
was constructed.Is it possible to add this or is there a reason why this was omitted?
The text was updated successfully, but these errors were encountered: