feat(config): simplify list command and add subcommand aliases
- config list: remove --long option, always display URL - config list: add ls alias (#[command(alias = "ls")]) - config delete: add rm and remove aliases (#[command(aliases = ["remove", "rm"])]) - README: update config list and config delete examples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -53,7 +53,7 @@ List registered remote hosts.
|
||||
|
||||
```shell
|
||||
mdrs config list
|
||||
mdrs config list -l
|
||||
mdrs config ls
|
||||
```
|
||||
|
||||
### config delete
|
||||
@@ -62,6 +62,7 @@ Remove a registered remote host.
|
||||
|
||||
```shell
|
||||
mdrs config delete neurodata
|
||||
mdrs config rm neurodata
|
||||
```
|
||||
|
||||
### login
|
||||
|
||||
@@ -100,7 +100,7 @@ pub fn config_update(remote: &str, url: &str) -> Result<(), Box<dyn std::error::
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn config_list(long: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn config_list() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let path = config_path();
|
||||
if !path.exists() {
|
||||
return Ok(());
|
||||
@@ -114,12 +114,8 @@ pub fn config_list(long: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if sec == "default" {
|
||||
continue;
|
||||
}
|
||||
if !long {
|
||||
println!("{}:", sec);
|
||||
} else {
|
||||
let url = props.get("url").and_then(|v| v.clone()).unwrap_or_default();
|
||||
println!("{}:\t{}", sec, url);
|
||||
}
|
||||
let url = props.get("url").and_then(|v| v.clone()).unwrap_or_default();
|
||||
println!("{}:\t{}", sec, url);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ pub enum ConfigSubcommand {
|
||||
/// Update an existing remote host
|
||||
Update(ConfigUpdateArgs),
|
||||
/// List all remote hosts
|
||||
#[command(alias = "ls")]
|
||||
List(ConfigListArgs),
|
||||
/// Delete a remote host
|
||||
#[command(aliases = ["remove", "rm"])]
|
||||
Delete(ConfigDeleteArgs),
|
||||
}
|
||||
|
||||
@@ -25,10 +27,7 @@ pub struct ConfigUpdateArgs {
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub struct ConfigListArgs {
|
||||
#[arg(short, long)]
|
||||
pub long: bool,
|
||||
}
|
||||
pub struct ConfigListArgs {}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub struct ConfigDeleteArgs {
|
||||
|
||||
+2
-2
@@ -161,8 +161,8 @@ fn main() {
|
||||
handle_error(e);
|
||||
}
|
||||
}
|
||||
ConfigSubcommand::List(args) => {
|
||||
if let Err(e) = crate::commands::config::config_list(args.long) {
|
||||
ConfigSubcommand::List(_) => {
|
||||
if let Err(e) = crate::commands::config::config_list() {
|
||||
handle_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user