@@ -24,6 +24,10 @@ use wayland::protocols::overlap_notify::OverlapNotifyState;
2424
2525use crate :: wayland:: handlers:: compositor:: client_compositor_state;
2626
27+ use clap_lex:: RawArgs ;
28+
29+ use std:: error:: Error ;
30+
2731pub mod backend;
2832pub mod config;
2933pub mod dbus;
@@ -95,7 +99,30 @@ impl State {
9599 }
96100}
97101
98- fn main ( ) -> Result < ( ) > {
102+ fn main ( ) -> Result < ( ) , Box < dyn Error > > {
103+ let raw_args = RawArgs :: from_args ( ) ;
104+ let mut cursor = raw_args. cursor ( ) ;
105+ let git_hash = option_env ! ( "GIT_HASH" ) . unwrap_or ( "unknown" ) ;
106+
107+ // Parse the arguments
108+ while let Some ( arg) = raw_args. next_os ( & mut cursor) {
109+ match arg. to_str ( ) {
110+ Some ( "--help" ) | Some ( "-h" ) => {
111+ print_help ( env ! ( "CARGO_PKG_VERSION" ) , git_hash) ;
112+ return Ok ( ( ) ) ;
113+ }
114+ Some ( "--version" ) | Some ( "-V" ) => {
115+ println ! (
116+ "cosmic-comp {} (git commit {})" ,
117+ env!( "CARGO_PKG_VERSION" ) ,
118+ git_hash
119+ ) ;
120+ return Ok ( ( ) ) ;
121+ }
122+ _ => { }
123+ }
124+ }
125+
99126 // setup logger
100127 logger:: init_logger ( ) ?;
101128 info ! ( "Cosmic starting up!" ) ;
@@ -193,6 +220,21 @@ fn main() -> Result<()> {
193220 Ok ( ( ) )
194221}
195222
223+ fn print_help ( version : & str , git_rev : & str ) {
224+ println ! (
225+ r#"cosmic-comp {version} (git commit {git_rev})
226+ 227+
228+ Designed for the COSMIC™ desktop environment, cosmic-comp is a Wayland Compositor.
229+
230+ Project home page: https://github.com/pop-os/cosmic-comp
231+
232+ Options:
233+ -h, --help Show this message
234+ -v, --version Show the version of cosmic-comp"#
235+ ) ;
236+ }
237+
196238fn init_wayland_display (
197239 event_loop : & mut EventLoop < state:: State > ,
198240) -> Result < ( DisplayHandle , OsString ) > {
0 commit comments