summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/cli.rs
blob: 2c1aeba375617f542a8cf5057a4156e23c8b0a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use crate::setup::Setup;
use crate::{
    consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV},
    input::options::CliOptions,
};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Default, Debug, Clone, Serialize, Deserialize)]
#[structopt(name = "zellij")]
pub struct CliArgs {
    /// Maximum panes on screen, caution: opening more panes will close old ones
    #[structopt(long)]
    pub max_panes: Option<usize>,

    /// Change where zellij looks for layouts and plugins
    #[structopt(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)]
    pub server: Option<PathBuf>,

    /// Specify name of a new session
    #[structopt(long, short)]
    pub session: Option<String>,

    /// Name of a layout file in the layout directory
    #[structopt(short, long, parse(from_os_str))]
    pub layout: Option<PathBuf>,

    /// Path to a layout yaml file
    #[structopt(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))]
    pub config: Option<PathBuf>,

    /// Change where zellij looks for the configuration directory
    #[structopt(long, env=ZELLIJ_CONFIG_DIR_ENV, parse(from_os_str))]
    pub config_dir: Option<PathBuf>,

    #[structopt(subcommand)]
    pub command: Option<Command>,

    #[structopt(short, long)]
    pub debug: bool,
}

#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)]
pub enum Command {
    /// Change the behaviour of zellij
    #[structopt(name = "options")]
    Options(CliOptions),

    /// 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 SessionCommand {
    /// Change the behaviour of zellij
    #[structopt(name = "options")]
    Options(CliOptions),
}

#[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: Option<String>,

        /// Create a session if one does not exist.
        #[structopt(short, long)]
        create: bool,

        /// Number of the session index in the active sessions ordered creation date.
        #[structopt(long)]
        index: Option<usize>,

        /// Change the behaviour of zellij
        #[structopt(subcommand, name = "options")]
        options: Option<SessionCommand>,
    },

    /// Kill the specific session
    #[structopt(alias = "k")]
    KillSession {
        /// Name of target session
        target_session: Option<String>,
    },

    /// Kill all sessions
    #[structopt(alias = "ka")]
    KillAllSessions {
        /// Automatic yes to prompts
        #[structopt(short, long)]
        yes: bool,
    },
}