-
Notifications
You must be signed in to change notification settings - Fork 152
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
Stop doing automatic author, about and version #217
Comments
I think the goal should be to default to a reasonable approximation of platform convention, similar to how Qt will try to default to matching the look of the target platform's GUI. By that logic:
In short, I'd keep |
I like the general idea to move into saner defaults and I think the changes you proposed are a step into the right direction. So just ping me as soon as you decided what to do and I will help to implement it. But I also think we will run into some odds based on the default behavior of clap and I think it's worth to push a bit more on their side to get rid of them instead of working on structopt internal fixes. This mostly includes the following topics:
|
Which supports my point that "it competes with rustdoc for what purpose the struct's docstring should serve." (I see it as a situation comparable to not implementing |
I'd say:
|
@TeXitoi Do you need any help on this? I'm going to have a vacation for a week, I'm quite familiar with the codebase and I'd love to make use of the upcoming features so just tell me what are you going to do and we may work it out. |
@CreepySkeleton That would be great, I have difficulties to find enough time to do that. I propose:
Also, at the same time, can you populate the CHANGELOG.md with your changes, I forgot to ask for that in your PR. Thanks for your contribution. |
Personally I like the current behavior as I think that it provides the best defaults for the majority of use cases and looks more pleasant. I'm also fine with not being in par with clap philosophy here. Although, I understand why it's going to change, and I'll be also fine with that. As an alternative might I suggest to preserve the current behavior but also enhance structopt to generate E.g. #[derive(StructOpt)]
#[structopt(version = "1.0")] // I want only version to be displayed in --help
struct Opt {
...
}
fn get_options() -> Opt {
Opt::from_args_custom()
} |
It does, but it's not just about "majority of use cases", there are also "default behavior doesn't break anything" considerations. My case as an example: I travel quite a lot with my job and sometimes I have no access to my own laptop. (Un)Fortunately, I tend to stay close to my friends so I often ask them to borrow theirs. Most of them have their own cargo installations with their own credentials, and I must admit that literally each one of my projects that needs command-line args parsing uses structopt. I'm sure you can see where we're going here - it wasn't just once when I accidentally started a project using wrong author credentials, thanks god they were closed-sourced and I had the authority to rewrite the history. (I also tend to forget to check git credentials but that's another story). Also see @ssokolow comment about leaking internal comments into the public usage message. So here's the point: now 9/10 of structopt users are happy with the default behavior and 1/10 users get f..reaked up if they aren't careful enough. With this changes we would have: 9/10 users will have to use
Sorry, I don't get it. Could you please explain how |
But aren't they f..reaked up anyway by having the wrong credentials in
Currently we have Lines 582 to 589 in 5dfa606
I propose to rewrite it as following /// Gets the struct from the command line arguments. Print the
/// error message and quit the program in case of failure.
fn from_args() -> Self
where
Self: Sized,
{
Self::from_clap(&Self::clap()
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.get_matches()
)
} And provide another function alongside which looks as /// Gets the struct from the command line arguments. Print the
/// error message and quit the program in case of failure. Default
/// entries from Cargo.toml will not be populated
fn from_args_custom() -> Self
where
Self: Sized,
{
Self::from_clap(&Self::clap().get_matches())
} It will be fully backward compatible way. However, it might have drawback that |
I don't want a That's an API design choice, there is no good or bad somution, only traid of. That would be only me, I'd do my proposition for clap consistency. But clap is not really thought with no version in mind, and that's why I propose to keep version. Also, note that the about thing is only about the description from the toml. The doc comment thing is some other thing, not related to this issue. And for the author thing, I prefer the no author by default, more consistent with others and clap's defaults. |
@TeXitoi I found some time and I'm working on it now, should be done by tomorrow. Just to be sure I get it right, feel free to correct:
|
Exact, except:
Error is not needed, just |
Exactly my point, people tend to stick to patterns they got used to, in my experience such explicit errors save lots of hours and sanity. The only thing - issuing a warning is impossible on stable rust so it's going to have to be a hard error.
It shouldn't - an extra |
Since the begining, structopt use the CARGO_PKG environment variables to populate version, about and authors if not provided. As sometime you don't want that to be setted, there is an ugly hack that, if you do
author = ""
, the magic is removed.That's not so in par with the clap philosophy, as these setters are not called by default on raw clap.
Thus I propose to remove the ugly hack, don't use CARGO_PKG by default, but add without argument options to set these fiels using the CARGO_PKG, i.e.
became
and
became
To anyone reading this, what do you think?
Would fix #172 and maybe #173
cc @sphynx @killercup @kbknapp @ssokolow @robinst @0ndorio
The text was updated successfully, but these errors were encountered: