rust3ds / cargo-3ds

Cargo command to work with Nintendo 3DS project binaries.
Apache License 2.0
58 stars 10 forks source link

Cleanup and Rewrite using Clap crate #21

Closed SteveCookTU closed 2 years ago

SteveCookTU commented 2 years ago

Clap has come a long way with now incorporating Structopt on the inside. It is my CLI building crate of choice so I put this PR together as an example. Everything is the same for the core functions, I only had to change the parsing and remove the need for the CargoCommand struct. The usage print out isn't as verbose as the original but more customization can be done using the builder rather than derive macros.

Hopefully this is a good start!

Ref issue #1

SteveCookTU commented 2 years ago

Also to note, I believe having the possible commands to pass to cargo being defined is a little stronger and also easier to control and test.

It should be doable to add more though with using defaults for the enum and having the "extra" command be included in the cargo_opts field.

SteveCookTU commented 2 years ago

With the derive method of defining the parser this is what the usage looks like.

cargo-3ds 

USAGE:
    cargo-3ds.exe <CMD> [CARGO_OPTS]...

ARGS:
    <CMD>              [possible values: build, run, test, check, clippy]
    <CARGO_OPTS>...

OPTIONS:
    -h, --help    Print help information

If switching to the builder method I believe there is a lot more customization but I haven't personally used it before. Always something new to learn!

SteveCookTU commented 2 years ago

What I thought was cargo producing the error was actually clap reading the leading hyphens as flags. It now passes all cargo flags directly as typed.

AzureMarker commented 2 years ago

I'm seeing this issue right now:

$ cargo 3ds clippy --example hello-world
error: "3ds" isn't a valid value for '<CMD>'
        [possible values: build, run, test, check, clippy]

For more information try --help
SteveCookTU commented 2 years ago

I'm seeing this issue right now:

$ cargo 3ds clippy --example hello-world
error: "3ds" isn't a valid value for '<CMD>'
        [possible values: build, run, test, check, clippy]

For more information try --help

I missed the note that cargo-3ds isn't supported and it should be run as cargo 3ds so I'll fix that to follow the original usage.

Meziu commented 2 years ago

@AzureMarker if you have nothing to add we mag merge this.

SteveCookTU commented 2 years ago

Made one last change to remove the need for the commands directory. Was leftover from the original design idea I had but wasn't needed in the end.

AzureMarker commented 2 years ago

Taking a quick look now to see if there's anything I see that's blocking.