forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBc658424Ivan Molodetskikh2 years ago1277 commits

cli.rs93 lines, 2.9 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 ///
17 /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
18 /// command line argument takes precedence.
19 #[arg(short, long)]
20 pub config: Option<PathBuf>,
21 /// Import environment globally to systemd and D-Bus, run D-Bus services.
22 ///
23 /// Set this flag in a systemd service started by your display manager, or when running
24 /// manually as your main compositor instance. Do not set when running as a nested window, or
25 /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.
26 #[arg(long)]
27 pub session: bool,
28 /// Command to run upon compositor startup.
29 #[arg(last = true)]
30 pub command: Vec<OsString>,
31
32 #[command(subcommand)]
33 pub subcommand: Option<Sub>,
34}
35
36#[derive(Subcommand)]
37pub enum Sub {
38 /// Communicate with the running niri instance.
39 Msg {
40 #[command(subcommand)]
41 msg: Msg,
42 /// Format output as JSON.
43 #[arg(short, long)]
44 json: bool,
45 },
46 /// Validate the config file.
47 Validate {
48 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
49 ///
50 /// This can also be set with the `NIRI_CONFIG` environment variable. If both are set, the
51 /// command line argument takes precedence.
52 #[arg(short, long)]
53 config: Option<PathBuf>,
54 },
55 /// Cause a panic to check if the backtraces are good.
56 Panic,
57}
58
59#[derive(Subcommand)]
60pub enum Msg {
61 /// List connected outputs.
62 Outputs,
63 /// List workspaces.
64 Workspaces,
65 /// Print information about the focused window.
66 FocusedWindow,
67 /// Print information about the focused output.
68 FocusedOutput,
69 /// Perform an action.
70 Action {
71 #[command(subcommand)]
72 action: Action,
73 },
74 /// Change output configuration temporarily.
75 ///
76 /// The configuration is changed temporarily and not saved into the config file. If the output
77 /// configuration subsequently changes in the config file, these temporary changes will be
78 /// forgotten.
79 Output {
80 /// Output name.
81 ///
82 /// Run `niri msg outputs` to see the output names.
83 #[arg()]
84 output: String,
85 /// Configuration to apply.
86 #[command(subcommand)]
87 action: OutputAction,
88 },
89 /// Print the version of the running niri instance.
90 Version,
91 /// Request an error from the running niri instance.
92 RequestError,
93}