forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBf2ce84bYuya Nishihara2 years ago1130 commits

cli.rs87 lines, 2.6 KiBHistoryRawDownload
1use std::ffi::OsString;
2use std::path::PathBuf;
3
4use clap::{Parser, Subcommand};
5use niri_ipc::{Action, OutputAction};
6
7use crate::utils::version;
8
9#[derive(Parser)]
10#[command(author, version = version(), about, long_about = None)]
11#[command(args_conflicts_with_subcommands = true)]
12#[command(subcommand_value_name = "SUBCOMMAND")]
13#[command(subcommand_help_heading = "Subcommands")]
14pub struct Cli {
15 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
16 #[arg(short, long)]
17 pub config: Option<PathBuf>,
18 /// Import environment globally to systemd and D-Bus, run D-Bus services.
19 ///
20 /// Set this flag in a systemd service started by your display manager, or when running
21 /// manually as your main compositor instance. Do not set when running as a nested window, or
22 /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.
23 #[arg(long)]
24 pub session: bool,
25 /// Command to run upon compositor startup.
26 #[arg(last = true)]
27 pub command: Vec<OsString>,
28
29 #[command(subcommand)]
30 pub subcommand: Option<Sub>,
31}
32
33#[derive(Subcommand)]
34pub enum Sub {
35 /// Communicate with the running niri instance.
36 Msg {
37 #[command(subcommand)]
38 msg: Msg,
39 /// Format output as JSON.
40 #[arg(short, long)]
41 json: bool,
42 },
43 /// Validate the config file.
44 Validate {
45 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
46 #[arg(short, long)]
47 config: Option<PathBuf>,
48 },
49 /// Cause a panic to check if the backtraces are good.
50 Panic,
51}
52
53#[derive(Subcommand)]
54pub enum Msg {
55 /// List connected outputs.
56 Outputs,
57 /// List workspaces.
58 Workspaces,
59 /// Print information about the focused window.
60 FocusedWindow,
61 /// Print information about the focused output.
62 FocusedOutput,
63 /// Perform an action.
64 Action {
65 #[command(subcommand)]
66 action: Action,
67 },
68 /// Change output configuration temporarily.
69 ///
70 /// The configuration is changed temporarily and not saved into the config file. If the output
71 /// configuration subsequently changes in the config file, these temporary changes will be
72 /// forgotten.
73 Output {
74 /// Output name.
75 ///
76 /// Run `niri msg outputs` to see the output names.
77 #[arg()]
78 output: String,
79 /// Configuration to apply.
80 #[command(subcommand)]
81 action: OutputAction,
82 },
83 /// Print the version of the running niri instance.
84 Version,
85 /// Request an error from the running niri instance.
86 RequestError,
87}