Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use clap for handling CLI args #2215

Open
onur-ozkan opened this issue Sep 11, 2024 · 0 comments
Open

use clap for handling CLI args #2215

onur-ozkan opened this issue Sep 11, 2024 · 0 comments
Labels

Comments

@onur-ozkan
Copy link
Member

Currently, the help flag is handled in this way:

fn help() {
const HELP_MSG: &str = r#"Command-line options.
The first command-line argument is special and designates the mode.
help .. Display this message.
btc2kmd {WIF or BTC} .. Convert a BTC WIF into a KMD WIF.
events .. Listen to a feed coming from a separate MM daemon and print it to stdout.
vanity {substring} .. Tries to find an address with the given substring.
update_config {SRC} {DST} .. Update the configuration of coins from the SRC config and save it to DST file.
{JSON configuration} .. Run the MarketMaker daemon.
Some (but not all) of the JSON configuration parameters (* - required):

And the CLI arguments are managed like this:

if first_arg == Some("update_config") {
match on_update_config(&args_os) {
Ok(_) => println!("Success"),
Err(e) => eprintln!("{}", e),
}
return;
}
if first_arg == Some("--version") || first_arg == Some("-v") || first_arg == Some("version") {
println!("AtomicDEX API: {version}");
return;
}
if first_arg == Some("--help") || first_arg == Some("-h") || first_arg == Some("help") {
help();
return;
}

Nor approach is sustainable/maintainable and they could get unsynced/outdated easily. Use an appropiete library (like clap with derive support) that handles all these automatically. Providing the autocomplete files could be a nice additional feature as well.

Neither approach is sustainable or maintainable and they can easily become outdated or unsynced. Ideally we should use clap (with derive support to handle them on the type level) to handle these automatically. By using clap we can generate the autocomplete files too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant