feat: add help and version command line arguments
This commit is contained in:
parent
e00d8df43a
commit
5b383f669b
4 changed files with 87 additions and 0 deletions
38
Cargo.lock
generated
38
Cargo.lock
generated
|
|
@ -195,6 +195,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.97"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "apply"
|
name = "apply"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
@ -1159,6 +1165,7 @@ dependencies = [
|
||||||
"greetd_ipc",
|
"greetd_ipc",
|
||||||
"i18n-embed",
|
"i18n-embed",
|
||||||
"i18n-embed-fl",
|
"i18n-embed-fl",
|
||||||
|
"lexopt",
|
||||||
"libcosmic",
|
"libcosmic",
|
||||||
"log",
|
"log",
|
||||||
"logind-zbus",
|
"logind-zbus",
|
||||||
|
|
@ -1170,6 +1177,7 @@ dependencies = [
|
||||||
"shlex",
|
"shlex",
|
||||||
"tokio",
|
"tokio",
|
||||||
"upower_dbus",
|
"upower_dbus",
|
||||||
|
"vergen",
|
||||||
"wayland-client",
|
"wayland-client",
|
||||||
"xdg",
|
"xdg",
|
||||||
"xkb-data",
|
"xkb-data",
|
||||||
|
|
@ -3187,6 +3195,12 @@ version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexopt"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.171"
|
version = "0.2.171"
|
||||||
|
|
@ -3689,6 +3703,15 @@ dependencies = [
|
||||||
"syn 2.0.100",
|
"syn 2.0.100",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_threads"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc"
|
name = "objc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
|
@ -5257,7 +5280,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618"
|
checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deranged",
|
"deranged",
|
||||||
|
"itoa",
|
||||||
|
"libc",
|
||||||
"num-conv",
|
"num-conv",
|
||||||
|
"num_threads",
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
"serde",
|
"serde",
|
||||||
"time-core",
|
"time-core",
|
||||||
|
|
@ -5662,6 +5688,18 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vergen"
|
||||||
|
version = "8.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2990d9ea5967266ea0ccf413a4aa5c42a93dbcfda9cb49a97de6931726b12566"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"cfg-if",
|
||||||
|
"rustversion",
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ name = "cosmic-greeter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
vergen = { version = "8", features = ["git", "gitcl"] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4", features = ["unstable-locales"] }
|
chrono = { version = "0.4", features = ["unstable-locales"] }
|
||||||
cosmic-bg-config.workspace = true
|
cosmic-bg-config.workspace = true
|
||||||
|
|
@ -42,6 +45,8 @@ nix = { workspace = true, optional = true }
|
||||||
upower_dbus = { git = "https://github.com/pop-os/dbus-settings-bindings", rev = "badfc6a", optional = true }
|
upower_dbus = { git = "https://github.com/pop-os/dbus-settings-bindings", rev = "badfc6a", optional = true }
|
||||||
# Required for some features
|
# Required for some features
|
||||||
zbus = { workspace = true, optional = true }
|
zbus = { workspace = true, optional = true }
|
||||||
|
# CLI arguments
|
||||||
|
lexopt = "0.3.0"
|
||||||
# Internationalization
|
# Internationalization
|
||||||
i18n-embed = { version = "0.14", features = [
|
i18n-embed = { version = "0.14", features = [
|
||||||
"fluent-system",
|
"fluent-system",
|
||||||
|
|
|
||||||
5
build.rs
Normal file
5
build.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
use vergen::EmitBuilder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
EmitBuilder::builder().git_sha(true).emit().unwrap();
|
||||||
|
}
|
||||||
39
src/main.rs
39
src/main.rs
|
|
@ -3,7 +3,30 @@
|
||||||
|
|
||||||
use cosmic_greeter::{greeter, locker};
|
use cosmic_greeter::{greeter, locker};
|
||||||
|
|
||||||
|
use lexopt::{Arg, Parser};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let mut parser = Parser::from_env();
|
||||||
|
|
||||||
|
// Parse the arguments
|
||||||
|
while let Some(arg) = parser.next()? {
|
||||||
|
match arg {
|
||||||
|
Arg::Short('h') | Arg::Long("help") => {
|
||||||
|
print_help(env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA"));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Arg::Short('v') | Arg::Long("version") => {
|
||||||
|
println!(
|
||||||
|
"cosmic-greeter {} (git commit {})",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
env!("VERGEN_GIT_SHA")
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match pwd::Passwd::current_user() {
|
match pwd::Passwd::current_user() {
|
||||||
Some(current_user) => match current_user.name.as_str() {
|
Some(current_user) => match current_user.name.as_str() {
|
||||||
"cosmic-greeter" => greeter::main(),
|
"cosmic-greeter" => greeter::main(),
|
||||||
|
|
@ -12,3 +35,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
_ => Err("failed to determine current user".into()),
|
_ => Err("failed to determine current user".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_help(version: &str, git_rev: &str) {
|
||||||
|
println!(
|
||||||
|
r#"cosmic-greeter {version} (git commit {git_rev})
|
||||||
|
System76 <info@system76.com>
|
||||||
|
|
||||||
|
Designed for the COSMIC™ desktop environment, cosmic-greeter is a libcosmic
|
||||||
|
frontend for greetd which can be run inside of cosmic-comp.
|
||||||
|
|
||||||
|
Project home page: https://github.com/pop-os/cosmic-greeter
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this message
|
||||||
|
-v, --version Show the version of cosmic-greeter"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue