Conversation
|
I'd like some feedback on the documentation, as well as any bugs/kinks that still need to ironed out. |
|
I'm not really sure why the Travis build is failing; it seems to still be looking for |
|
To fix Travis, you must update the structopt-derive version in the dev-depedencies of the Cargo.toml at the root of the project. |
|
And please update everything to 0.1.0, else we can't do non breaking change version. |
|
It's updated at 72d9d35, so it seems to be something else. |
|
This commit update only the README.md. |
|
Nevermind, you're right, I'm an idiot. I think I accidentally clobbered updating the |
|
Question about these two lines from the examples: struct MakeCookie {
#[structopt(name = "supervisor", default_value = "Puck")]
supervising_faerie: Option<String>,
// ...Is it necessary for the |
TeXitoi
left a comment
There was a problem hiding this comment.
Great!
A rapid first read. I'll do a deeper read soon.
structopt-derive/src/lib.rs
Outdated
| //! `Arg::with_name()` call (default to the field name). | ||
| //! Then, each field of the struct not marked as a subcommand corresponds | ||
| //! to a `clap::Arg`. As with the struct attributes, every method of | ||
| //! `clap::Arg`in the form of `fn function_name(self, &str)` can be used |
structopt-derive/src/lib.rs
Outdated
| //! } | ||
| //! ``` | ||
| //! | ||
| //! ## Subcomamnds |
structopt-derive/src/lib.rs
Outdated
| //! #[structopt(name = "make-cookie")] | ||
| //! struct MakeCookie { | ||
| //! #[structopt(name = "supervisor", default_value = "Puck")] | ||
| //! supervising_faerie: Option<String>, |
There was a problem hiding this comment.
With default value you don't want an option
|
Great doc ! Thanks for the corrections of my frenchy English ;-) |
|
@ErichDonGubler You're right, will change that. |
|
@williamyaoh: Looks like something like this fails right now: enum Subcommand {
Something // Fails here
}Adding curly braces fixes it, but shouldn't be necessary: enum Subcommand {
Something {}
} |
|
@ErichDonGubler Yup, that's already on the Things to be improved list above already. It's fixable, though it's not trivial to do. |
|
@ErichDonGubler Fixed at 4ff50e6. It ended up being simpler than I thought it would be. |
|
Regarding downcasing of subcommand names by default: I can see the convenience, but on the other hand, it also means using "magic" from the programmer's perspective, where names that they never typed become part of the interface of their program. I'm not sure whether the convenience outweighs the confusion over the exact mechanism of translation of subcommand names. What does everyone else think? I think the actual semantics would be to translate all identifiers into kebab case, if no #[derive(StructOpt)]
enum DoStuff {
DoTheThing
}would automatically produce a command #[derive(StructOpt)]
struct DoOtherStuff {
useful_information: bool
}would automatically produce a command |
|
I think translation to kebab-case is an important feature. I prefer this feature to be in another PR, it'll let me the time to validate this one soon. |
TeXitoi
left a comment
There was a problem hiding this comment.
Great work! Only small feedbacks.
structopt-derive/src/lib.rs
Outdated
| quote!( .arg(_structopt::clap::Arg::with_name(stringify!(#name)) #modifier #(#from_attr)*) ) | ||
| }); | ||
|
|
||
| assert!(subcmds.len() <= 1, "cannot have more than one nested subcommand"); |
There was a problem hiding this comment.
I prefer this assert be just after the declaration, it explain why we have collect
src/lib.rs
Outdated
| fn clap<'a, 'b>() -> clap::App<'a, 'b>; | ||
|
|
||
| /// Add this app's arguments/subcommands to another `clap::App`. | ||
| fn augment_clap<'a, 'b>(clap::App<'a, 'b>) -> clap::App<'a, 'b>; |
There was a problem hiding this comment.
I'm not a big fan of this, but I don't have any better idea.
There was a problem hiding this comment.
I could move that function into a inherent impl block for each type; that would remove it from cluttering up the StructOpt documentation, at least, which I think is the real issue.
|
All right, unless someone else finds a bug in the subcommand-related stuff, that looks to be everything. |
|
@TeXitoi Do you need anything else from me before merging? |
|
Yes a computer. I'm in vacation.
Le 14 juillet 2017 04:37:20 GMT+02:00, William Yao <notifications@github.com> a écrit :
…
@TeXitoi Do you need anything else from me before merging?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#17 (comment)
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
|
|
Published, thanks for your work! |
fix a bunch of clippy warnings
See #1 for detailed discussion of this feature.
Adds the ability to use
#[derive(StructOpt)]on enums, thereby allowing the creation/easy parsing ofclap::SubCommands.This is not a breaking change.
Things that can still be improved:
#[derive(StructOpt)]on structs or to changing argument names from_to-)aboutattribute/doc comments on subcommand variants for help messagesOther stuff
There are some commits that don't technically have anything to do with adding subcommands in:
structoptdocumentation to thestructopt-derivedocumentationstructoptandstructopt-deriveto 0.1.0structopt-derivedocumentation for clarityDetailed documentation has been added to the
structopt-derivecrate specifying how to use the new subcommand functionality. Reproduced here:Subcomamnds
Some applications, like
git, support "subcommands;" an extra command thatis used to differentiate what the application should do. With
git, thesewould be
add,init,fetch,commit, for a few examples.claphas this functionality, sostructoptsupports this through enums:Using
derive(StructOpt)on an enum instead of a struct will producea
clap::Appthat only takes subcommands. Sogit add,git fetch,and
git commitwould be commands allowed for the above example.structoptalso provides support for applications where certain flagsneed to apply to all subcommands, as well as nested subcommands:
Marking a field with
structopt(subcommand)will add the subcommands of thedesignated enum to the current
clap::App. The designated enum must alsobe derived
StructOpt. So the above example would take the followingcommands:
make-cookie pound 50make-cookie sparkle -mmm --color "green"make-cookie finish 130 glaze 3Optional subcommands
A nested subcommand can be marked optional: