Move from structopt to clap-derive

This commit is contained in:
elkowar 2022-09-03 18:41:23 +02:00
parent 2c3b3ff260
commit b4d47956b5
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
5 changed files with 103 additions and 84 deletions

104
Cargo.lock generated
View file

@ -183,12 +183,51 @@ dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"strsim 0.8.0",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap"
version = "3.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"once_cell",
"strsim 0.10.0",
"termcolor",
"textwrap 0.15.0",
]
[[package]]
name = "clap_derive"
version = "3.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "codemap"
version = "0.1.3"
@ -373,6 +412,7 @@ dependencies = [
"bincode",
"cairo-rs",
"cairo-sys-rs",
"clap 3.2.20",
"codespan-reporting",
"derive_more",
"eww_shared_util",
@ -400,7 +440,6 @@ dependencies = [
"simple-signal",
"simplexpr",
"smart-default",
"structopt",
"sysinfo",
"tokio",
"tokio-util",
@ -701,7 +740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a68131a662b04931e71891fb14aaf65ee4b44d08e8abc10f49e77418c86c64"
dependencies = [
"anyhow",
"heck 0.4.0",
"heck",
"proc-macro-crate",
"proc-macro-error",
"proc-macro2",
@ -737,7 +776,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89369b06ea6eb94b38f5f2014d0d2c5a57c1b5e5bfd2e328f9cec96e6ca92448"
dependencies = [
"beef",
"clap",
"clap 2.34.0",
"codemap",
"indexmap",
"lasso",
@ -847,15 +886,6 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heck"
version = "0.4.0"
@ -1194,6 +1224,12 @@ version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "output_vt100"
version = "0.1.3"
@ -1780,28 +1816,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.26"
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck 0.3.3",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
@ -1818,7 +1836,7 @@ version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
dependencies = [
"heck 0.4.0",
"heck",
"proc-macro2",
"quote",
"rustversion",
@ -1858,7 +1876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
dependencies = [
"cfg-expr",
"heck 0.4.0",
"heck",
"pkg-config",
"toml",
"version-compare",
@ -1903,6 +1921,12 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "thiserror"
version = "1.0.32"
@ -2004,12 +2028,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-width"
version = "0.1.9"

View file

@ -35,7 +35,7 @@ bincode = "1.3"
anyhow = "1.0"
derive_more = "0.99"
maplit = "1"
structopt = "0.3"
clap = {version = "3.0", features = ["derive"] }
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
extend = "1"

View file

@ -1,8 +1,8 @@
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use eww_shared_util::VarName;
use serde::{Deserialize, Serialize};
use simplexpr::dynval::DynVal;
use structopt::StructOpt;
use yuck::{
config::{monitor::MonitorIdentifier, window_geometry::AnchorPoint},
value::Coords,
@ -24,155 +24,157 @@ pub struct Opt {
pub no_daemonize: bool,
}
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Parser, Debug, Serialize, Deserialize, PartialEq)]
#[clap(author = "ElKowar")]
#[clap(version, about)]
struct RawOpt {
/// Write out debug logs. (To read the logs, run `eww logs`).
#[structopt(long = "debug", global = true)]
#[clap(long = "debug", global = true)]
log_debug: bool,
/// override path to configuration directory (directory that contains eww.yuck and eww.scss)
#[structopt(short, long, global = true)]
#[clap(short, long, global = true)]
config: Option<std::path::PathBuf>,
/// Watch the log output after executing the command
#[structopt(long = "logs", global = true)]
#[clap(long = "logs", global = true)]
show_logs: bool,
/// Avoid daemonizing eww.
#[structopt(long = "no-daemonize", global = true)]
#[clap(long = "no-daemonize", global = true)]
no_daemonize: bool,
/// Restart the daemon completely before running the command
#[structopt(long = "restart", global = true)]
#[clap(long = "restart", global = true)]
restart: bool,
#[structopt(subcommand)]
#[clap(subcommand)]
action: Action,
}
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)]
pub enum Action {
/// Start the Eww daemon.
#[structopt(name = "daemon", alias = "d")]
#[clap(name = "daemon", alias = "d")]
Daemon,
#[structopt(flatten)]
#[clap(flatten)]
ClientOnly(ActionClientOnly),
#[structopt(flatten)]
#[clap(flatten)]
WithServer(ActionWithServer),
}
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)]
pub enum ActionClientOnly {
/// Print and watch the eww logs
#[structopt(name = "logs")]
#[clap(name = "logs")]
Logs,
}
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
#[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)]
pub enum ActionWithServer {
/// Ping the eww server, checking if it is reachable.
#[structopt(name = "ping")]
#[clap(name = "ping")]
Ping,
/// Update the value of a variable, in a running eww instance
#[structopt(name = "update", alias = "u")]
#[clap(name = "update", alias = "u")]
Update {
/// variable_name="new_value"-pairs that will be updated
#[structopt(parse(try_from_str = parse_var_update_arg))]
#[clap(parse(try_from_str = parse_var_update_arg))]
mappings: Vec<(VarName, DynVal)>,
},
/// Open the GTK debugger
#[structopt(name = "inspector", alias = "debugger")]
#[clap(name = "inspector", alias = "debugger")]
OpenInspector,
/// Open a window
#[structopt(name = "open", alias = "o")]
#[clap(name = "open", alias = "o")]
OpenWindow {
/// Name of the window you want to open.
window_name: String,
/// The identifier of the monitor the window should open on
#[structopt(long)]
#[clap(long)]
screen: Option<MonitorIdentifier>,
/// The position of the window, where it should open. (i.e.: 200x100)
#[structopt(short, long)]
#[clap(short, long)]
pos: Option<Coords>,
/// The size of the window to open (i.e.: 200x100)
#[structopt(short, long)]
#[clap(short, long)]
size: Option<Coords>,
/// Sidepoint of the window, formatted like "top right"
#[structopt(short, long)]
#[clap(short, long)]
anchor: Option<AnchorPoint>,
/// If the window is already open, close it instead
#[structopt(long = "toggle")]
#[clap(long = "toggle")]
should_toggle: bool,
},
/// Open multiple windows at once.
/// NOTE: This will in the future be part of eww open, and will then be removed.
#[structopt(name = "open-many")]
#[clap(name = "open-many")]
OpenMany {
windows: Vec<String>,
/// If a window is already open, close it instead
#[structopt(long = "toggle")]
#[clap(long = "toggle")]
should_toggle: bool,
},
/// Close the given windows
#[structopt(name = "close", alias = "c")]
#[clap(name = "close", alias = "c")]
CloseWindows { windows: Vec<String> },
/// Reload the configuration
#[structopt(name = "reload", alias = "r")]
#[clap(name = "reload", alias = "r")]
Reload,
/// Kill the eww daemon
#[structopt(name = "kill", alias = "k")]
#[clap(name = "kill", alias = "k")]
KillServer,
/// Close all windows, without killing the daemon
#[structopt(name = "close-all", alias = "ca")]
#[clap(name = "close-all", alias = "ca")]
CloseAll,
/// Prints the variables used in all currently open window
#[structopt(name = "state")]
#[clap(name = "state")]
ShowState {
/// Shows all variables, including not currently used ones
#[structopt(short, long)]
#[clap(short, long)]
all: bool,
},
/// Get the value of a variable if defined
#[structopt(name = "get")]
#[clap(name = "get")]
GetVar { name: String },
/// Print the names of all configured windows. Windows with a * in front of them are currently opened.
#[structopt(name = "windows")]
#[clap(name = "windows")]
ShowWindows,
/// Print out the widget structure as seen by eww.
///
/// This may be useful if you are facing issues with how eww is interpreting your configuration,
/// and to provide additional context to the eww developers if you are filing a bug.
#[structopt(name = "debug")]
#[clap(name = "debug")]
ShowDebug,
/// Print out the scope graph structure in graphviz dot format.
#[structopt(name = "graph")]
#[clap(name = "graph")]
ShowGraph,
}
impl Opt {
pub fn from_env() -> Self {
let raw: RawOpt = StructOpt::from_args();
let raw: RawOpt = RawOpt::parse();
raw.into()
}
}

View file

@ -61,4 +61,3 @@ impl<T> DiagResultExt<T> for DiagResult<T> {
self.map_err(|e| e.note(note))
}
}

View file

@ -2,9 +2,9 @@
#![allow(unused)]
#![feature(try_blocks)]
pub mod ast_error;
pub mod config;
pub mod error;
pub mod format_diagnostic;
pub mod parser;
pub mod value;
pub mod ast_error;