diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-08-07 10:39:53 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-08-21 17:02:26 +0200 |
| commit | 9a873502c9401887bdca445874ea216ff341b982 (patch) | |
| tree | 46a65d076d5d6fd9d7c317247b4a137fa06828fb /mullvad-cli/src/cmds | |
| parent | e0a64fd53906b9dcdeb0b5b17bc3885964f342f4 (diff) | |
| download | mullvadvpn-9a873502c9401887bdca445874ea216ff341b982.tar.xz mullvadvpn-9a873502c9401887bdca445874ea216ff341b982.zip | |
Unify `mullvad custom-list` subcommands `get` and `list`
`mullvad custom-list list` now optionally takes an argument: A name of a
custom list to retrieve.
Diffstat (limited to 'mullvad-cli/src/cmds')
| -rw-r--r-- | mullvad-cli/src/cmds/custom_lists.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/mullvad-cli/src/cmds/custom_lists.rs b/mullvad-cli/src/cmds/custom_lists.rs index 9c0770a442..3c93b7eb75 100644 --- a/mullvad-cli/src/cmds/custom_lists.rs +++ b/mullvad-cli/src/cmds/custom_lists.rs @@ -9,11 +9,13 @@ use mullvad_types::{ #[derive(Subcommand, Debug)] pub enum CustomList { - /// Get names of custom lists - List, - - /// Retrieve a custom list by its name - Get { name: String }, + /// List all custom lists or retrieve a custom list by its name + List { + // TODO: Would be cool to provide dynamic auto-completion: + // https://github.com/clap-rs/clap/issues/1232 + /// A custom list. If omitted, all custom lists are shown + name: Option<String>, + }, /// Create a new custom list Create { name: String }, @@ -42,8 +44,8 @@ pub enum CustomList { impl CustomList { pub async fn handle(self) -> Result<()> { match self { - CustomList::List => Self::list().await, - CustomList::Get { name } => Self::get(name).await, + CustomList::List { name: None } => Self::list().await, + CustomList::List { name: Some(name) } => Self::get(name).await, CustomList::Create { name } => Self::create_list(name).await, CustomList::Add { name, location } => Self::add_location(name, location).await, CustomList::Remove { name, location } => Self::remove_location(name, location).await, @@ -52,6 +54,7 @@ impl CustomList { } } + /// Print all custom lists. async fn list() -> Result<()> { let mut rpc = MullvadProxyClient::new().await?; for custom_list in rpc.list_custom_lists().await? { @@ -60,6 +63,8 @@ impl CustomList { Ok(()) } + /// Print a specific custom list (if it exists). + /// If the list does not exist, print an error. async fn get(name: String) -> Result<()> { let mut rpc = MullvadProxyClient::new().await?; let custom_list = rpc.get_custom_list(name).await?; |
