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
feature: CLI good first issue Good for newcomers priority: medium Moderately important tasks that should be completed but are not urgent.

Comments

@onur-ozkan
Copy link
Member

onur-ozkan commented Sep 11, 2024

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;
}

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.

@shamardy shamardy added the priority: medium Moderately important tasks that should be completed but are not urgent. label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: CLI good first issue Good for newcomers priority: medium Moderately important tasks that should be completed but are not urgent.
Projects
None yet
Development

No branches or pull requests

2 participants