diff options
author | Marcin Puc <5671049+tranzystorek-io@users.noreply.github.com> | 2022-01-23 20:59:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-23 20:59:03 +0100 |
commit | e58b67ce2ed839dd8cbd2dadabc6e092b0e0b96a (patch) | |
tree | e7f4597ed4832cf655691dffdb92a9c32b9407a3 /zellij-utils/src | |
parent | 5f86dc4fd0542e5db22c0263fdaac8cb0309b440 (diff) |
chore(deps): update arg parsing to clap v3 (#1017)
* Update arg parsing to clap v3
* Ignore shell argument case
Diffstat (limited to 'zellij-utils/src')
-rw-r--r-- | zellij-utils/src/cli.rs | 56 | ||||
-rw-r--r-- | zellij-utils/src/input/options.rs | 36 | ||||
-rw-r--r-- | zellij-utils/src/lib.rs | 2 | ||||
-rw-r--r-- | zellij-utils/src/setup.rs | 23 |
4 files changed, 59 insertions, 58 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index 2c1aeba37..03bf8db4d 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -3,111 +3,111 @@ use crate::{ consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV}, input::options::CliOptions, }; +use clap::{Parser, Subcommand}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(StructOpt, Default, Debug, Clone, Serialize, Deserialize)] -#[structopt(name = "zellij")] +#[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)] +#[clap(version, name = "zellij")] pub struct CliArgs { /// Maximum panes on screen, caution: opening more panes will close old ones - #[structopt(long)] + #[clap(long)] pub max_panes: Option<usize>, /// Change where zellij looks for layouts and plugins - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] pub data_dir: Option<PathBuf>, /// Run server listening at the specified socket path - #[structopt(long, parse(from_os_str), hidden = true)] + #[clap(long, parse(from_os_str), hide = true)] pub server: Option<PathBuf>, /// Specify name of a new session - #[structopt(long, short)] + #[clap(long, short)] pub session: Option<String>, /// Name of a layout file in the layout directory - #[structopt(short, long, parse(from_os_str))] + #[clap(short, long, parse(from_os_str))] pub layout: Option<PathBuf>, /// Path to a layout yaml file - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] pub layout_path: Option<PathBuf>, /// Change where zellij looks for the configuration file - #[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV, parse(from_os_str))] + #[clap(short, long, env = ZELLIJ_CONFIG_FILE_ENV, parse(from_os_str))] pub config: Option<PathBuf>, /// Change where zellij looks for the configuration directory - #[structopt(long, env=ZELLIJ_CONFIG_DIR_ENV, parse(from_os_str))] + #[clap(long, env = ZELLIJ_CONFIG_DIR_ENV, parse(from_os_str))] pub config_dir: Option<PathBuf>, - #[structopt(subcommand)] + #[clap(subcommand)] pub command: Option<Command>, - #[structopt(short, long)] + #[clap(short, long)] pub debug: bool, } -#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] +#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)] pub enum Command { /// Change the behaviour of zellij - #[structopt(name = "options")] + #[clap(name = "options")] Options(CliOptions), /// Setup zellij and check its configuration - #[structopt(name = "setup")] + #[clap(name = "setup")] Setup(Setup), /// Explore existing zellij sessions - #[structopt(flatten)] + #[clap(flatten)] Sessions(Sessions), } -#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] +#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)] pub enum SessionCommand { /// Change the behaviour of zellij - #[structopt(name = "options")] + #[clap(name = "options")] Options(CliOptions), } -#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] +#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)] pub enum Sessions { /// List active sessions - #[structopt(alias = "ls")] + #[clap(alias = "ls")] ListSessions, /// Attach to session - #[structopt(alias = "a")] + #[clap(alias = "a")] Attach { /// Name of the session to attach to. session_name: Option<String>, /// Create a session if one does not exist. - #[structopt(short, long)] + #[clap(short, long)] create: bool, /// Number of the session index in the active sessions ordered creation date. - #[structopt(long)] + #[clap(long)] index: Option<usize>, /// Change the behaviour of zellij - #[structopt(subcommand, name = "options")] + #[clap(subcommand, name = "options")] options: Option<SessionCommand>, }, /// Kill the specific session - #[structopt(alias = "k")] + #[clap(alias = "k")] KillSession { /// Name of target session target_session: Option<String>, }, /// Kill all sessions - #[structopt(alias = "ka")] + #[clap(alias = "ka")] KillAllSessions { /// Automatic yes to prompts - #[structopt(short, long)] + #[clap(short, long)] yes: bool, }, } diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index d8bef694b..41f241f69 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -1,12 +1,12 @@ //! Handles cli and configuration options use crate::cli::Command; +use clap::{ArgEnum, Args}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::str::FromStr; -use structopt::StructOpt; use zellij_tile::data::InputMode; -#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, ArgEnum)] pub enum OnForceClose { #[serde(alias = "quit")] Quit, @@ -32,7 +32,7 @@ impl FromStr for OnForceClose { } } -#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)] +#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, Args)] /// Options that can be set either through the config file, /// or cli flags - cli flags should take precedence over the config file /// TODO: In order to correctly parse boolean flags, this is currently split @@ -40,43 +40,43 @@ impl FromStr for OnForceClose { pub struct Options { /// Allow plugins to use a more simplified layout /// that is compatible with more fonts (true or false) - #[structopt(long)] + #[clap(long)] #[serde(default)] pub simplified_ui: Option<bool>, /// Set the default theme - #[structopt(long)] + #[clap(long)] pub theme: Option<String>, /// Set the default mode - #[structopt(long)] + #[clap(long, arg_enum, hide_possible_values = true)] pub default_mode: Option<InputMode>, /// Set the default shell - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] pub default_shell: Option<PathBuf>, /// Set the layout_dir, defaults to /// subdirectory of config dir - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] pub layout_dir: Option<PathBuf>, - #[structopt(long)] + #[clap(long)] #[serde(default)] /// Set the handling of mouse events (true or false) /// Can be temporarily bypassed by the [SHIFT] key pub mouse_mode: Option<bool>, - #[structopt(long)] + #[clap(long)] #[serde(default)] /// Set display of the pane frames (true or false) pub pane_frames: Option<bool>, - #[structopt(long)] + #[clap(long)] #[serde(default)] /// Mirror session when multiple users are connected (true or false) pub mirror_session: Option<bool>, /// Set behaviour on force close (quit or detach) - #[structopt(long)] + #[clap(long, arg_enum, hide_possible_values = true)] pub on_force_close: Option<OnForceClose>, - #[structopt(long)] + #[clap(long)] pub scroll_buffer_size: Option<usize>, /// Switch to using a user supplied command for clipboard instead of OSC52 - #[structopt(long)] + #[clap(long)] #[serde(default)] pub copy_command: Option<String>, } @@ -173,17 +173,17 @@ impl Options { } } -#[derive(Clone, Default, Debug, PartialEq, StructOpt, Serialize, Deserialize)] +#[derive(Clone, Default, Debug, PartialEq, Args, Serialize, Deserialize)] /// Options that can be set through cli flags /// boolean flags end up toggling boolean options in `Options` pub struct CliOptions { /// Disable handling of mouse events - #[structopt(long, conflicts_with("mouse-mode"))] + #[clap(long, conflicts_with("mouse-mode"))] pub disable_mouse_mode: bool, /// Disable display of pane frames - #[structopt(long, conflicts_with("pane-frames"))] + #[clap(long, conflicts_with("pane-frames"))] pub no_pane_frames: bool, - #[structopt(flatten)] + #[clap(flatten)] options: Options, } diff --git a/zellij-utils/src/lib.rs b/zellij-utils/src/lib.rs index 4ccb25f5e..7115c1b46 100644 --- a/zellij-utils/src/lib.rs +++ b/zellij-utils/src/lib.rs @@ -12,13 +12,13 @@ pub mod setup; pub mod shared; pub use async_std; +pub use clap; pub use interprocess; pub use libc; pub use nix; pub use serde; pub use serde_yaml; pub use signal_hook; -pub use structopt; pub use termion; pub use vte; pub use zellij_tile; diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 0de857249..565e72c9d 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -10,12 +10,13 @@ use crate::{ options::Options, }, }; +use clap::{Args, IntoApp}; +use clap_complete::Shell; use directories_next::BaseDirs; use serde::{Deserialize, Serialize}; use std::{ convert::TryFrom, fmt::Write as FmtWrite, io::Write, path::Path, path::PathBuf, process, }; -use structopt::StructOpt; const CONFIG_LOCATION: &str = ".config/zellij"; const CONFIG_NAME: &str = "config.yaml"; @@ -124,25 +125,25 @@ pub fn dump_specified_layout(layout: &str) -> std::io::Result<()> { } } -#[derive(Debug, Default, Clone, StructOpt, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Args, Serialize, Deserialize)] pub struct Setup { /// Dump the default configuration file to stdout - #[structopt(long)] + #[clap(long)] pub dump_config: bool, /// Disables loading of configuration file at default location, /// loads the defaults that zellij ships with - #[structopt(long)] + #[clap(long)] pub clean: bool, /// Checks the configuration of zellij and displays /// currently used directories - #[structopt(long)] + #[clap(long)] pub check: bool, /// Dump the specified layout file to stdout - #[structopt(long)] + #[clap(long)] pub dump_layout: Option<String>, /// Generates completion for the specified shell - #[structopt(long)] + #[clap(long, value_name = "SHELL")] pub generate_completion: Option<String>, } @@ -231,7 +232,7 @@ impl Setup { } if let Some(shell) = &self.generate_completion { - Self::generate_completion(shell.into()); + Self::generate_completion(shell); std::process::exit(0); } @@ -376,8 +377,8 @@ impl Setup { Ok(()) } - fn generate_completion(shell: String) { - let shell = match shell.parse() { + fn generate_completion(shell: &str) { + let shell: Shell = match shell.to_lowercase().parse() { Ok(shell) => shell, _ => { eprintln!("Unsupported shell: {}", shell); @@ -385,7 +386,7 @@ impl Setup { } }; let mut out = std::io::stdout(); - CliArgs::clap().gen_completions_to("zellij", shell, &mut out); + clap_complete::generate(shell, &mut CliArgs::into_app(), "zellij", &mut out); } } |