Argument support with clap_lex
This commit is contained in:
parent
956734aa62
commit
2b8a3f7894
3 changed files with 60 additions and 9 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
|
@ -1,6 +1,6 @@
|
||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ab_glyph"
|
name = "ab_glyph"
|
||||||
|
|
@ -609,6 +609,12 @@ dependencies = [
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clipboard-win"
|
name = "clipboard-win"
|
||||||
version = "5.4.0"
|
version = "5.4.0"
|
||||||
|
|
@ -804,6 +810,7 @@ dependencies = [
|
||||||
"bitflags 2.8.0",
|
"bitflags 2.8.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"calloop 0.14.2",
|
"calloop 0.14.2",
|
||||||
|
"clap_lex",
|
||||||
"cosmic-comp-config",
|
"cosmic-comp-config",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
"cosmic-protocols",
|
"cosmic-protocols",
|
||||||
|
|
@ -1467,7 +1474,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2520,7 +2527,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "id_tree"
|
name = "id_tree"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
source = "git+https://github.com/Drakulix/id-tree.git?branch=feature/copy_clone#632a57d6d49160e18d7300fa7edae52281ec5482"
|
source = "git+https://github.com/Drakulix/id-tree.git?branch=feature%2Fcopy_clone#632a57d6d49160e18d7300fa7edae52281ec5482"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"snowflake",
|
"snowflake",
|
||||||
]
|
]
|
||||||
|
|
@ -2912,7 +2919,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.48.5",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -4386,7 +4393,7 @@ dependencies = [
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.4.15",
|
"linux-raw-sys 0.4.15",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -4987,7 +4994,7 @@ dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -5280,7 +5287,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69fff37da548239c3bf9e64a12193d261e8b22b660991c6fd2df057c168f435f"
|
checksum = "69fff37da548239c3bf9e64a12193d261e8b22b660991c6fd2df057c168f435f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"windows-targets 0.48.5",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -5960,7 +5967,7 @@ version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ rustix = { version = "0.38.32", features = ["process"] }
|
||||||
smallvec = "1.13.2"
|
smallvec = "1.13.2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
reis = { version = "0.4", features = ["calloop"] }
|
reis = { version = "0.4", features = ["calloop"] }
|
||||||
|
# CLI arguments
|
||||||
|
clap_lex = "0.7"
|
||||||
|
|
||||||
[dependencies.id_tree]
|
[dependencies.id_tree]
|
||||||
branch = "feature/copy_clone"
|
branch = "feature/copy_clone"
|
||||||
|
|
|
||||||
44
src/main.rs
44
src/main.rs
|
|
@ -24,6 +24,10 @@ use wayland::protocols::overlap_notify::OverlapNotifyState;
|
||||||
|
|
||||||
use crate::wayland::handlers::compositor::client_compositor_state;
|
use crate::wayland::handlers::compositor::client_compositor_state;
|
||||||
|
|
||||||
|
use clap_lex::RawArgs;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod dbus;
|
pub mod dbus;
|
||||||
|
|
@ -95,7 +99,30 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let raw_args = RawArgs::from_args();
|
||||||
|
let mut cursor = raw_args.cursor();
|
||||||
|
let git_hash = option_env!("GIT_HASH").unwrap_or("unknown");
|
||||||
|
|
||||||
|
// Parse the arguments
|
||||||
|
while let Some(arg) = raw_args.next_os(&mut cursor) {
|
||||||
|
match arg.to_str() {
|
||||||
|
Some("--help") | Some("-h") => {
|
||||||
|
print_help(env!("CARGO_PKG_VERSION"), git_hash);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Some("--version") | Some("-V") => {
|
||||||
|
println!(
|
||||||
|
"cosmic-comp {} (git commit {})",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
git_hash
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setup logger
|
// setup logger
|
||||||
logger::init_logger()?;
|
logger::init_logger()?;
|
||||||
info!("Cosmic starting up!");
|
info!("Cosmic starting up!");
|
||||||
|
|
@ -193,6 +220,21 @@ fn main() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_help(version: &str, git_rev: &str) {
|
||||||
|
println!(
|
||||||
|
r#"cosmic-comp {version} (git commit {git_rev})
|
||||||
|
System76 <info@system76.com>
|
||||||
|
|
||||||
|
Designed for the COSMIC™ desktop environment, cosmic-comp is a Wayland Compositor.
|
||||||
|
|
||||||
|
Project home page: https://github.com/pop-os/cosmic-comp
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this message
|
||||||
|
-v, --version Show the version of cosmic-comp"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn init_wayland_display(
|
fn init_wayland_display(
|
||||||
event_loop: &mut EventLoop<state::State>,
|
event_loop: &mut EventLoop<state::State>,
|
||||||
) -> Result<(DisplayHandle, OsString)> {
|
) -> Result<(DisplayHandle, OsString)> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue