rust-secure-code / cargo-supply-chain

Gather author, contributor and publisher data on crates in your dependency graph.
Apache License 2.0
313 stars 18 forks source link

Split argument validation into a separate function #40

Closed Shnatsel closed 2 years ago

Shnatsel commented 3 years ago

Right now argument validation and actually calling the subcommands is lumped together in one function:

https://github.com/rust-secure-code/cargo-supply-chain/blob/776ab090333f4f07a61fe0e66386e49bae5eff45/src/main.rs#L65-L67

This makes them impossible to unit-test and necessitates manual calls to eprintln_help() in multiple places instead of just one in main on any validation error.

We should split argument validation to another function that accepts Args and returns Result<ValidatedArgs>, where ValidatedArgs is something like:

enum ValidatedArgs {
    Help {command: Option<String>},
    Update {cache_max_age: Duration},
    Crates {cache_max_age: Duration, metadata_args: Vec<String>},
    Publishers {cache_max_age: Duration, metadata_args: Vec<String>},
}

And make dispatch_command accept that as an argument.