chore(deps): update arg parsing to clap v3 (#1017)

* Update arg parsing to clap v3
* Ignore shell argument case
This commit is contained in:
Marcin Puc 2022-01-23 20:59:03 +01:00 committed by GitHub
parent 5f86dc4fd0
commit e58b67ce2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 127 deletions

141
Cargo.lock generated
View file

@ -26,15 +26,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "ansi_term" name = "ansi_term"
version = "0.12.1" version = "0.12.1"
@ -338,17 +329,41 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375"
dependencies = [ dependencies = [
"ansi_term 0.11.0",
"atty", "atty",
"bitflags", "bitflags",
"strsim 0.8.0", "clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim",
"termcolor",
"textwrap", "textwrap",
"unicode-width", ]
"vec_map",
[[package]]
name = "clap_complete"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d044e9db8cd0f68191becdeb5246b7462e4cf0c069b19ae00d1bf3fa9889498d"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153"
dependencies = [
"heck 0.4.0",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
] ]
[[package]] [[package]]
@ -603,7 +618,7 @@ dependencies = [
"ident_case", "ident_case",
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.10.0", "strsim",
"syn", "syn",
] ]
@ -980,6 +995,12 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -1259,9 +1280,9 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.3.4" version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]] [[package]]
name = "memmap2" name = "memmap2"
@ -1438,6 +1459,15 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "parking" name = "parking"
version = "2.0.0" version = "2.0.0"
@ -2030,7 +2060,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
name = "status-bar" name = "status-bar"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term",
"colored", "colored",
"lazy_static", "lazy_static",
"rand 0.8.4", "rand 0.8.4",
@ -2059,42 +2089,12 @@ dependencies = [
"vte", "vte",
] ]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "structopt"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.20.0" version = "0.20.0"
@ -2107,7 +2107,7 @@ version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149"
dependencies = [ dependencies = [
"heck", "heck 0.3.3",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -2152,7 +2152,7 @@ dependencies = [
name = "tab-bar" name = "tab-bar"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term",
"colored", "colored",
"unicode-width", "unicode-width",
"zellij-tile", "zellij-tile",
@ -2179,6 +2179,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "terminal_size" name = "terminal_size"
version = "0.1.17" version = "0.1.17"
@ -2216,12 +2225,9 @@ dependencies = [
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [
"unicode-width",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
@ -2435,12 +2441,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.3"
@ -2816,6 +2816,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
@ -2864,7 +2873,7 @@ dependencies = [
name = "zellij-server" name = "zellij-server"
version = "0.25.0" version = "0.25.0"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term",
"async-trait", "async-trait",
"base64", "base64",
"byteorder", "byteorder",
@ -2890,6 +2899,7 @@ dependencies = [
name = "zellij-tile" name = "zellij-tile"
version = "0.25.0" version = "0.25.0"
dependencies = [ dependencies = [
"clap",
"serde", "serde",
"serde_json", "serde_json",
"strum", "strum",
@ -2900,7 +2910,7 @@ dependencies = [
name = "zellij-tile-utils" name = "zellij-tile-utils"
version = "0.25.0" version = "0.25.0"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term",
] ]
[[package]] [[package]]
@ -2911,6 +2921,8 @@ dependencies = [
"async-std", "async-std",
"backtrace", "backtrace",
"bincode", "bincode",
"clap",
"clap_complete",
"colored", "colored",
"colorsys", "colorsys",
"crossbeam", "crossbeam",
@ -2927,7 +2939,6 @@ dependencies = [
"serde_yaml", "serde_yaml",
"signal-hook", "signal-hook",
"strip-ansi-escapes", "strip-ansi-escapes",
"structopt",
"strum", "strum",
"tempfile", "tempfile",
"termion", "termion",

View file

@ -5,14 +5,14 @@ mod sessions;
mod tests; mod tests;
use zellij_utils::{ use zellij_utils::{
clap::Parser,
cli::{CliArgs, Command, Sessions}, cli::{CliArgs, Command, Sessions},
logging::*, logging::*,
structopt::StructOpt,
}; };
fn main() { fn main() {
configure_logger(); configure_logger();
let opts = CliArgs::from_args(); let opts = CliArgs::parse();
if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command { if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command {
commands::list_sessions(); commands::list_sessions();

View file

@ -7,6 +7,7 @@ description = "A small client-side library for writing Zellij plugins"
license = "MIT" license = "MIT"
[dependencies] [dependencies]
clap = { version = "3.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
strum = "0.20.0" strum = "0.20.0"

View file

@ -1,3 +1,4 @@
use clap::ArgEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt; use std::fmt;
use std::str::FromStr; use std::str::FromStr;
@ -82,7 +83,7 @@ pub enum Event {
} }
/// Describes the different input modes, which change the way that keystrokes will be interpreted. /// Describes the different input modes, which change the way that keystrokes will be interpreted.
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize, ArgEnum)]
pub enum InputMode { pub enum InputMode {
/// In `Normal` mode, input is always written to the terminal, except for the shortcuts leading /// In `Normal` mode, input is always written to the terminal, except for the shortcuts leading
/// to other modes /// to other modes

View file

@ -12,6 +12,8 @@ license = "MIT"
anyhow = "1.0.45" anyhow = "1.0.45"
backtrace = "0.3.55" backtrace = "0.3.55"
bincode = "1.3.1" bincode = "1.3.1"
clap = { version = "3.0", features = ["derive", "env"] }
clap_complete = "3.0"
colored = "2.0.0" colored = "2.0.0"
colorsys = "0.6.5" colorsys = "0.6.5"
crossbeam = "0.8.0" crossbeam = "0.8.0"
@ -26,7 +28,6 @@ serde_yaml = "0.8"
serde_json = "1.0" serde_json = "1.0"
signal-hook = "0.3" signal-hook = "0.3"
strip-ansi-escapes = "0.1.0" strip-ansi-escapes = "0.1.0"
structopt = "0.3"
strum = "0.20.0" strum = "0.20.0"
termion = "1.5.0" termion = "1.5.0"
thiserror = "1.0.30" thiserror = "1.0.30"

View file

@ -3,111 +3,111 @@ use crate::{
consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV}, consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV},
input::options::CliOptions, input::options::CliOptions,
}; };
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt, Default, Debug, Clone, Serialize, Deserialize)] #[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)]
#[structopt(name = "zellij")] #[clap(version, name = "zellij")]
pub struct CliArgs { pub struct CliArgs {
/// Maximum panes on screen, caution: opening more panes will close old ones /// Maximum panes on screen, caution: opening more panes will close old ones
#[structopt(long)] #[clap(long)]
pub max_panes: Option<usize>, pub max_panes: Option<usize>,
/// Change where zellij looks for layouts and plugins /// 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>, pub data_dir: Option<PathBuf>,
/// Run server listening at the specified socket path /// 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>, pub server: Option<PathBuf>,
/// Specify name of a new session /// Specify name of a new session
#[structopt(long, short)] #[clap(long, short)]
pub session: Option<String>, pub session: Option<String>,
/// Name of a layout file in the layout directory /// 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>, pub layout: Option<PathBuf>,
/// Path to a layout yaml file /// Path to a layout yaml file
#[structopt(long, parse(from_os_str))] #[clap(long, parse(from_os_str))]
pub layout_path: Option<PathBuf>, pub layout_path: Option<PathBuf>,
/// Change where zellij looks for the configuration file /// 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>, pub config: Option<PathBuf>,
/// Change where zellij looks for the configuration directory /// 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>, pub config_dir: Option<PathBuf>,
#[structopt(subcommand)] #[clap(subcommand)]
pub command: Option<Command>, pub command: Option<Command>,
#[structopt(short, long)] #[clap(short, long)]
pub debug: bool, pub debug: bool,
} }
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] #[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum Command { pub enum Command {
/// Change the behaviour of zellij /// Change the behaviour of zellij
#[structopt(name = "options")] #[clap(name = "options")]
Options(CliOptions), Options(CliOptions),
/// Setup zellij and check its configuration /// Setup zellij and check its configuration
#[structopt(name = "setup")] #[clap(name = "setup")]
Setup(Setup), Setup(Setup),
/// Explore existing zellij sessions /// Explore existing zellij sessions
#[structopt(flatten)] #[clap(flatten)]
Sessions(Sessions), Sessions(Sessions),
} }
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] #[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum SessionCommand { pub enum SessionCommand {
/// Change the behaviour of zellij /// Change the behaviour of zellij
#[structopt(name = "options")] #[clap(name = "options")]
Options(CliOptions), Options(CliOptions),
} }
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] #[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum Sessions { pub enum Sessions {
/// List active sessions /// List active sessions
#[structopt(alias = "ls")] #[clap(alias = "ls")]
ListSessions, ListSessions,
/// Attach to session /// Attach to session
#[structopt(alias = "a")] #[clap(alias = "a")]
Attach { Attach {
/// Name of the session to attach to. /// Name of the session to attach to.
session_name: Option<String>, session_name: Option<String>,
/// Create a session if one does not exist. /// Create a session if one does not exist.
#[structopt(short, long)] #[clap(short, long)]
create: bool, create: bool,
/// Number of the session index in the active sessions ordered creation date. /// Number of the session index in the active sessions ordered creation date.
#[structopt(long)] #[clap(long)]
index: Option<usize>, index: Option<usize>,
/// Change the behaviour of zellij /// Change the behaviour of zellij
#[structopt(subcommand, name = "options")] #[clap(subcommand, name = "options")]
options: Option<SessionCommand>, options: Option<SessionCommand>,
}, },
/// Kill the specific session /// Kill the specific session
#[structopt(alias = "k")] #[clap(alias = "k")]
KillSession { KillSession {
/// Name of target session /// Name of target session
target_session: Option<String>, target_session: Option<String>,
}, },
/// Kill all sessions /// Kill all sessions
#[structopt(alias = "ka")] #[clap(alias = "ka")]
KillAllSessions { KillAllSessions {
/// Automatic yes to prompts /// Automatic yes to prompts
#[structopt(short, long)] #[clap(short, long)]
yes: bool, yes: bool,
}, },
} }

View file

@ -1,12 +1,12 @@
//! Handles cli and configuration options //! Handles cli and configuration options
use crate::cli::Command; use crate::cli::Command;
use clap::{ArgEnum, Args};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use structopt::StructOpt;
use zellij_tile::data::InputMode; use zellij_tile::data::InputMode;
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, ArgEnum)]
pub enum OnForceClose { pub enum OnForceClose {
#[serde(alias = "quit")] #[serde(alias = "quit")]
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, /// Options that can be set either through the config file,
/// or cli flags - cli flags should take precedence over 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 /// TODO: In order to correctly parse boolean flags, this is currently split
@ -40,43 +40,43 @@ impl FromStr for OnForceClose {
pub struct Options { pub struct Options {
/// Allow plugins to use a more simplified layout /// Allow plugins to use a more simplified layout
/// that is compatible with more fonts (true or false) /// that is compatible with more fonts (true or false)
#[structopt(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
pub simplified_ui: Option<bool>, pub simplified_ui: Option<bool>,
/// Set the default theme /// Set the default theme
#[structopt(long)] #[clap(long)]
pub theme: Option<String>, pub theme: Option<String>,
/// Set the default mode /// Set the default mode
#[structopt(long)] #[clap(long, arg_enum, hide_possible_values = true)]
pub default_mode: Option<InputMode>, pub default_mode: Option<InputMode>,
/// Set the default shell /// Set the default shell
#[structopt(long, parse(from_os_str))] #[clap(long, parse(from_os_str))]
pub default_shell: Option<PathBuf>, pub default_shell: Option<PathBuf>,
/// Set the layout_dir, defaults to /// Set the layout_dir, defaults to
/// subdirectory of config dir /// subdirectory of config dir
#[structopt(long, parse(from_os_str))] #[clap(long, parse(from_os_str))]
pub layout_dir: Option<PathBuf>, pub layout_dir: Option<PathBuf>,
#[structopt(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
/// Set the handling of mouse events (true or false) /// Set the handling of mouse events (true or false)
/// Can be temporarily bypassed by the [SHIFT] key /// Can be temporarily bypassed by the [SHIFT] key
pub mouse_mode: Option<bool>, pub mouse_mode: Option<bool>,
#[structopt(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
/// Set display of the pane frames (true or false) /// Set display of the pane frames (true or false)
pub pane_frames: Option<bool>, pub pane_frames: Option<bool>,
#[structopt(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
/// Mirror session when multiple users are connected (true or false) /// Mirror session when multiple users are connected (true or false)
pub mirror_session: Option<bool>, pub mirror_session: Option<bool>,
/// Set behaviour on force close (quit or detach) /// Set behaviour on force close (quit or detach)
#[structopt(long)] #[clap(long, arg_enum, hide_possible_values = true)]
pub on_force_close: Option<OnForceClose>, pub on_force_close: Option<OnForceClose>,
#[structopt(long)] #[clap(long)]
pub scroll_buffer_size: Option<usize>, pub scroll_buffer_size: Option<usize>,
/// Switch to using a user supplied command for clipboard instead of OSC52 /// Switch to using a user supplied command for clipboard instead of OSC52
#[structopt(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
pub copy_command: Option<String>, 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 /// Options that can be set through cli flags
/// boolean flags end up toggling boolean options in `Options` /// boolean flags end up toggling boolean options in `Options`
pub struct CliOptions { pub struct CliOptions {
/// Disable handling of mouse events /// Disable handling of mouse events
#[structopt(long, conflicts_with("mouse-mode"))] #[clap(long, conflicts_with("mouse-mode"))]
pub disable_mouse_mode: bool, pub disable_mouse_mode: bool,
/// Disable display of pane frames /// Disable display of pane frames
#[structopt(long, conflicts_with("pane-frames"))] #[clap(long, conflicts_with("pane-frames"))]
pub no_pane_frames: bool, pub no_pane_frames: bool,
#[structopt(flatten)] #[clap(flatten)]
options: Options, options: Options,
} }

View file

@ -12,13 +12,13 @@ pub mod setup;
pub mod shared; pub mod shared;
pub use async_std; pub use async_std;
pub use clap;
pub use interprocess; pub use interprocess;
pub use libc; pub use libc;
pub use nix; pub use nix;
pub use serde; pub use serde;
pub use serde_yaml; pub use serde_yaml;
pub use signal_hook; pub use signal_hook;
pub use structopt;
pub use termion; pub use termion;
pub use vte; pub use vte;
pub use zellij_tile; pub use zellij_tile;

View file

@ -10,12 +10,13 @@ use crate::{
options::Options, options::Options,
}, },
}; };
use clap::{Args, IntoApp};
use clap_complete::Shell;
use directories_next::BaseDirs; use directories_next::BaseDirs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
convert::TryFrom, fmt::Write as FmtWrite, io::Write, path::Path, path::PathBuf, process, convert::TryFrom, fmt::Write as FmtWrite, io::Write, path::Path, path::PathBuf, process,
}; };
use structopt::StructOpt;
const CONFIG_LOCATION: &str = ".config/zellij"; const CONFIG_LOCATION: &str = ".config/zellij";
const CONFIG_NAME: &str = "config.yaml"; 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 { pub struct Setup {
/// Dump the default configuration file to stdout /// Dump the default configuration file to stdout
#[structopt(long)] #[clap(long)]
pub dump_config: bool, pub dump_config: bool,
/// Disables loading of configuration file at default location, /// Disables loading of configuration file at default location,
/// loads the defaults that zellij ships with /// loads the defaults that zellij ships with
#[structopt(long)] #[clap(long)]
pub clean: bool, pub clean: bool,
/// Checks the configuration of zellij and displays /// Checks the configuration of zellij and displays
/// currently used directories /// currently used directories
#[structopt(long)] #[clap(long)]
pub check: bool, pub check: bool,
/// Dump the specified layout file to stdout /// Dump the specified layout file to stdout
#[structopt(long)] #[clap(long)]
pub dump_layout: Option<String>, pub dump_layout: Option<String>,
/// Generates completion for the specified shell /// Generates completion for the specified shell
#[structopt(long)] #[clap(long, value_name = "SHELL")]
pub generate_completion: Option<String>, pub generate_completion: Option<String>,
} }
@ -231,7 +232,7 @@ impl Setup {
} }
if let Some(shell) = &self.generate_completion { if let Some(shell) = &self.generate_completion {
Self::generate_completion(shell.into()); Self::generate_completion(shell);
std::process::exit(0); std::process::exit(0);
} }
@ -376,8 +377,8 @@ impl Setup {
Ok(()) Ok(())
} }
fn generate_completion(shell: String) { fn generate_completion(shell: &str) {
let shell = match shell.parse() { let shell: Shell = match shell.to_lowercase().parse() {
Ok(shell) => shell, Ok(shell) => shell,
_ => { _ => {
eprintln!("Unsupported shell: {}", shell); eprintln!("Unsupported shell: {}", shell);
@ -385,7 +386,7 @@ impl Setup {
} }
}; };
let mut out = std::io::stdout(); 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);
} }
} }