[WiP] moss: switch cli to use clap derive structs - #687
Conversation
b8a732b to
1d81a7f
Compare
15db4d6 to
ff813c4
Compare
ff776d2 to
8978b24
Compare
d9f7098 to
7b91bad
Compare
Not done yet, just capturing current progress. Signed-off-by: Rune Morling <ermo@aerynos.com>
Signed-off-by: Rune Morling <ermo@aerynos.com>
Signed-off-by: Rune Morling <ermo@aerynos.com>
Signed-off-by: Rune Morling <ermo@aerynos.com>
Signed-off-by: Rune Morling <ermo@aerynos.com>
7b91bad to
968cece
Compare
Rune said: "--upgrade-only is a misfeature. An index is supposed to be ABI-complete. Having packages installed from a previous index is thus ungood." And who am I to disagree!
cli::Error is currently 144 bytes large and clippy complains about that. To silence it, we heap allocate it. I consider this half a hack and we should ideally reduce Error's size, starting from client::Error.
968cece to
331a69d
Compare
Also move public API to the top of the file, for visibility.
|
The I think |
|
For ease of use, we might consider allowing What is your thinking on potentially allowing both |
Not a problem, I'll do that. But I want to highlight that a
Yes please 😄
I think I could just add a non-visible alias from clap_derive for that but to be honest, I don't think users will type unshortented "repository" or "package" unless forced to, as it is currently the case with "package". |
|
If we make moss help show |
331a69d to
ca00901
Compare
This PR migrates the CLI from function-based Clap declarations to clap_derive. clap_derive allows a declarative-like definition of the CLI command tree, so it's easier to maintain and extend.
Inside
moss/src/cliwe'll have a rootmod.rsfile and one module per each subcommand. Modules may be split into other submodules when the logic becomes complex and/or multiple tests are defined (e.g. for thepackagesubcommand).Each module will have a
Commandstruct withhandle()as its only public method. The signature of eachhandle()is not identical for allCommands, but depends on the logic it performs.Public structs/enum/functions will be at the top of each source file, private ones will be right below.
This PR fixes #196, but that issue plan functionalities that the moss backend does not yet support, and that's the reason why you'll see a bunch of
unimplemented!()calls across the PR.It also fixes #611.
Another thing I wanted to make consistent is the use verbs in their imperative conjugation instead of third-person, as these are commands. I also chose not to end phrases with a dot, like most programs out there.
I think the code could be cleaned a little (e.g. there are some Vec conversions I'm not sure they would be needed with more generic code), but that's out of the scope of this PR. I'm trying to introduce no functional and API changes here, except the parsing of CLI arguments: where possible, I'm leveraging Clap's automatic call of
TryFromto sanitize inputs, particularly for providers where I'm now passing theProviderstruct.TODO: print final CLI tree.