sketch an alternative structure using Clap beta#5
sketch an alternative structure using Clap beta#5danieleades wants to merge 2 commits intoOverkillGuy:masterfrom
Conversation
|
i'm updated this pull request to show how you can break this down into separate modules. Again, just a sketch. Take what's useful and ignore the rest! |
|
Ooh, good shout on the module-making, I tried my hand in the ongoing
|
there's no difference between the module structure for binary or library
yep! actually the module system is quite similar to python, except
|
|
This does look nice, but I'll likely adopt it once I've gone around the codebase a bunch on basic features, and find the basic |
here's a sketch of an alternative formulation of a way to structure a CLI app using the clap 3.0 beta (itself a port of structopt back in to the clap codebase)
I've not actually seen this pattern documented before, but I doubt I've invented it.
it gives you nice encapsulation, since by definition all of the required inputs are fields of the struct itself.
All of the extra stuff, like setting the binary name, the project version, the author, etc. are all done automatically by the derive macro based on the contents of
Cargo.toml(but can be overridden if you wish!) The implementation i've added here is completely equivalent to the original argument parsing logic.note I've used
io::Result<()>but that's probably not ideal if you're wanting something a little more human-readable. I recommend taking a look at these two crates-panic!messages for when things go very wrong