From d6fc7b04d14e8eeb5157cace639cc1d157766987 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Wed, 19 May 2021 18:09:22 +0530 Subject: [PATCH] add attach and list sessions subcommand to CliArgs --- src/main.rs | 6 +++--- zellij-client/src/lib.rs | 2 +- zellij-utils/src/cli.rs | 29 ++++++++++++++++++++++++++--- zellij-utils/src/input/config.rs | 6 +++--- zellij-utils/src/input/options.rs | 6 +++--- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index a970ce44..eb7f476b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::convert::TryFrom; use zellij_client::{os_input_output::get_client_os_input, start_client}; use zellij_server::{os_input_output::get_server_os_input, start_server}; use zellij_utils::{ - cli::{CliArgs, ConfigCli}, + cli::{CliArgs, Command}, consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, input::config::Config, logging::*, @@ -16,8 +16,8 @@ use zellij_utils::{ pub fn main() { let opts = CliArgs::from_args(); - if let Some(ConfigCli::Setup(setup)) = opts.option.clone() { - Setup::from_cli(&setup, &opts).expect("Failed to print to stdout"); + if let Some(Command::Setup(ref setup)) = opts.command { + Setup::from_cli(setup, &opts).expect("Failed to print to stdout"); } let config = match Config::try_from(&opts) { diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 9deb415e..4ff37706 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -101,7 +101,7 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C let mut command_is_executing = CommandIsExecuting::new(); - let config_options = Options::from_cli(&config.options, opts.option.clone()); + let config_options = Options::from_cli(&config.options, opts.command.clone()); let full_screen_ws = os_input.get_terminal_size_using_fd(0); let client_attributes = ClientAttributes { diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index 4b2fdbbf..87f929c7 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -17,7 +17,7 @@ pub struct CliArgs { pub data_dir: Option, /// Run server listening at the specified socket path - #[structopt(long, parse(from_os_str))] + #[structopt(long, parse(from_os_str), hidden = true)] pub server: Option, /// Name of a layout file in the layout directory @@ -37,14 +37,14 @@ pub struct CliArgs { pub config_dir: Option, #[structopt(subcommand)] - pub option: Option, + pub command: Option, #[structopt(short, long)] pub debug: bool, } #[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] -pub enum ConfigCli { +pub enum Command { /// Change the behaviour of zellij #[structopt(name = "options")] Options(Options), @@ -52,4 +52,27 @@ pub enum ConfigCli { /// Setup zellij and check its configuration #[structopt(name = "setup")] Setup(Setup), + + /// Explore existing zellij sessions + #[structopt(flatten)] + Sessions(Sessions), +} + +#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] +pub enum Sessions { + /// List active sessions + #[structopt(alias = "ls")] + ListSessions, + + /// Attach to session + #[structopt(alias = "a")] + Attach { + /// Name of the session to attach to. + session_name: String, + + /// Force attach- session will detach from the other + /// zellij client (if any) and attach to this. + #[structopt(long, short)] + force: bool, + }, } diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index a0341689..c4cf0cd7 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use super::keybinds::{Keybinds, KeybindsFromYaml}; use super::options::Options; -use crate::cli::{CliArgs, ConfigCli}; +use crate::cli::{CliArgs, Command}; use crate::setup; use serde::{Deserialize, Serialize}; @@ -60,7 +60,7 @@ impl TryFrom<&CliArgs> for Config { return Config::new(&path); } - if let Some(ConfigCli::Setup(setup)) = opts.option.clone() { + if let Some(Command::Setup(ref setup)) = opts.command { if setup.clean { return Config::from_default_assets(); } @@ -179,7 +179,7 @@ mod config_test { fn try_from_cli_args_with_option_clean() { use crate::setup::Setup; let mut opts = CliArgs::default(); - opts.option = Some(ConfigCli::Setup(Setup { + opts.command = Some(Command::Setup(Setup { clean: true, ..Setup::default() })); diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index 33625b65..f9724c20 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -1,5 +1,5 @@ //! Handles cli and configuration options -use crate::cli::ConfigCli; +use crate::cli::Command; use serde::{Deserialize, Serialize}; use structopt::StructOpt; @@ -35,8 +35,8 @@ impl Options { Options { simplified_ui } } - pub fn from_cli(&self, other: Option) -> Options { - if let Some(ConfigCli::Options(options)) = other { + pub fn from_cli(&self, other: Option) -> Options { + if let Some(Command::Options(options)) = other { Options::merge(&self, options) } else { self.to_owned()