feat: add help and version command line arguments

This commit is contained in:
LinuxBoy-96 2025-03-24 14:50:51 -04:00 committed by GitHub
parent e00d8df43a
commit 5b383f669b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 87 additions and 0 deletions

38
Cargo.lock generated
View file

@ -195,6 +195,12 @@ dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
[[package]]
name = "apply"
version = "0.3.0"
@ -1159,6 +1165,7 @@ dependencies = [
"greetd_ipc",
"i18n-embed",
"i18n-embed-fl",
"lexopt",
"libcosmic",
"log",
"logind-zbus",
@ -1170,6 +1177,7 @@ dependencies = [
"shlex",
"tokio",
"upower_dbus",
"vergen",
"wayland-client",
"xdg",
"xkb-data",
@ -3187,6 +3195,12 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lexopt"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
[[package]]
name = "libc"
version = "0.2.171"
@ -3689,6 +3703,15 @@ dependencies = [
"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]]
name = "objc"
version = "0.2.7"
@ -5257,7 +5280,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618"
dependencies = [
"deranged",
"itoa",
"libc",
"num-conv",
"num_threads",
"powerfmt",
"serde",
"time-core",
@ -5662,6 +5688,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "version_check"
version = "0.9.5"

View file

@ -3,6 +3,9 @@ name = "cosmic-greeter"
version = "0.1.0"
edition = "2024"
[build-dependencies]
vergen = { version = "8", features = ["git", "gitcl"] }
[dependencies]
chrono = { version = "0.4", features = ["unstable-locales"] }
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 }
# Required for some features
zbus = { workspace = true, optional = true }
# CLI arguments
lexopt = "0.3.0"
# Internationalization
i18n-embed = { version = "0.14", features = [
"fluent-system",

5
build.rs Normal file
View file

@ -0,0 +1,5 @@
use vergen::EmitBuilder;
fn main() {
EmitBuilder::builder().git_sha(true).emit().unwrap();
}

View file

@ -3,7 +3,30 @@
use cosmic_greeter::{greeter, locker};
use lexopt::{Arg, Parser};
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() {
Some(current_user) => match current_user.name.as_str() {
"cosmic-greeter" => greeter::main(),
@ -12,3 +35,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
_ => 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"#
);
}