add attach and list sessions subcommand to CliArgs
This commit is contained in:
parent
d13fc7cafa
commit
d6fc7b04d1
5 changed files with 36 additions and 13 deletions
|
|
@ -5,7 +5,7 @@ use std::convert::TryFrom;
|
||||||
use zellij_client::{os_input_output::get_client_os_input, start_client};
|
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_server::{os_input_output::get_server_os_input, start_server};
|
||||||
use zellij_utils::{
|
use zellij_utils::{
|
||||||
cli::{CliArgs, ConfigCli},
|
cli::{CliArgs, Command},
|
||||||
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
||||||
input::config::Config,
|
input::config::Config,
|
||||||
logging::*,
|
logging::*,
|
||||||
|
|
@ -16,8 +16,8 @@ use zellij_utils::{
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let opts = CliArgs::from_args();
|
let opts = CliArgs::from_args();
|
||||||
|
|
||||||
if let Some(ConfigCli::Setup(setup)) = opts.option.clone() {
|
if let Some(Command::Setup(ref setup)) = opts.command {
|
||||||
Setup::from_cli(&setup, &opts).expect("Failed to print to stdout");
|
Setup::from_cli(setup, &opts).expect("Failed to print to stdout");
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = match Config::try_from(&opts) {
|
let config = match Config::try_from(&opts) {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
|
||||||
|
|
||||||
let mut command_is_executing = CommandIsExecuting::new();
|
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 full_screen_ws = os_input.get_terminal_size_using_fd(0);
|
||||||
let client_attributes = ClientAttributes {
|
let client_attributes = ClientAttributes {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub struct CliArgs {
|
||||||
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))]
|
#[structopt(long, parse(from_os_str), hidden = true)]
|
||||||
pub server: Option<PathBuf>,
|
pub server: Option<PathBuf>,
|
||||||
|
|
||||||
/// Name of a layout file in the layout directory
|
/// Name of a layout file in the layout directory
|
||||||
|
|
@ -37,14 +37,14 @@ pub struct CliArgs {
|
||||||
pub config_dir: Option<PathBuf>,
|
pub config_dir: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
#[structopt(subcommand)]
|
||||||
pub option: Option<ConfigCli>,
|
pub command: Option<Command>,
|
||||||
|
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)]
|
#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)]
|
||||||
pub enum ConfigCli {
|
pub enum Command {
|
||||||
/// Change the behaviour of zellij
|
/// Change the behaviour of zellij
|
||||||
#[structopt(name = "options")]
|
#[structopt(name = "options")]
|
||||||
Options(Options),
|
Options(Options),
|
||||||
|
|
@ -52,4 +52,27 @@ pub enum ConfigCli {
|
||||||
/// Setup zellij and check its configuration
|
/// Setup zellij and check its configuration
|
||||||
#[structopt(name = "setup")]
|
#[structopt(name = "setup")]
|
||||||
Setup(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,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use super::keybinds::{Keybinds, KeybindsFromYaml};
|
use super::keybinds::{Keybinds, KeybindsFromYaml};
|
||||||
use super::options::Options;
|
use super::options::Options;
|
||||||
use crate::cli::{CliArgs, ConfigCli};
|
use crate::cli::{CliArgs, Command};
|
||||||
use crate::setup;
|
use crate::setup;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -60,7 +60,7 @@ impl TryFrom<&CliArgs> for Config {
|
||||||
return Config::new(&path);
|
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 {
|
if setup.clean {
|
||||||
return Config::from_default_assets();
|
return Config::from_default_assets();
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +179,7 @@ mod config_test {
|
||||||
fn try_from_cli_args_with_option_clean() {
|
fn try_from_cli_args_with_option_clean() {
|
||||||
use crate::setup::Setup;
|
use crate::setup::Setup;
|
||||||
let mut opts = CliArgs::default();
|
let mut opts = CliArgs::default();
|
||||||
opts.option = Some(ConfigCli::Setup(Setup {
|
opts.command = Some(Command::Setup(Setup {
|
||||||
clean: true,
|
clean: true,
|
||||||
..Setup::default()
|
..Setup::default()
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//! Handles cli and configuration options
|
//! Handles cli and configuration options
|
||||||
use crate::cli::ConfigCli;
|
use crate::cli::Command;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
|
@ -35,8 +35,8 @@ impl Options {
|
||||||
Options { simplified_ui }
|
Options { simplified_ui }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_cli(&self, other: Option<ConfigCli>) -> Options {
|
pub fn from_cli(&self, other: Option<Command>) -> Options {
|
||||||
if let Some(ConfigCli::Options(options)) = other {
|
if let Some(Command::Options(options)) = other {
|
||||||
Options::merge(&self, options)
|
Options::merge(&self, options)
|
||||||
} else {
|
} else {
|
||||||
self.to_owned()
|
self.to_owned()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue