remux/src/main.rs

73 lines
1.2 KiB
Rust
Raw Normal View History

2023-04-06 13:34:32 -04:00
use pico_args::Arguments;
mod command;
mod env;
2023-04-14 16:38:34 -04:00
mod error;
mod flag;
2024-01-23 16:45:58 -05:00
mod help;
mod state;
2023-04-06 13:34:32 -04:00
mod util;
2024-02-04 16:11:32 -05:00
use help::{ help, version };
use state::State;
2024-02-04 16:11:32 -05:00
static VERSION: &str = env!("CARGO_PKG_VERSION");
2024-01-23 16:45:58 -05:00
2023-04-06 13:34:32 -04:00
fn main() {
2024-02-04 16:07:24 -05:00
// collect args
2023-04-06 13:34:32 -04:00
let mut args = Arguments::from_env();
2024-02-04 16:07:24 -05:00
// consume flags
if args.contains(flag::HELP) {
2024-01-23 16:45:58 -05:00
help(&mut args);
return;
}
if args.contains(flag::VERSION) {
2024-02-04 16:11:32 -05:00
version();
return;
}
let mut state = State::new(&mut args);
let target = state.target();
2023-04-06 13:34:32 -04:00
2024-02-04 16:07:24 -05:00
// invoke subcommand function
match target.as_deref() {
Some("help")
2024-01-23 16:45:58 -05:00
=> help(&mut args),
None
=> command::share::context_action(&state),
2023-04-06 13:34:32 -04:00
2023-04-20 15:31:22 -04:00
Some("a" | "attach")
=> command::share::attach(&mut state),
2023-04-06 13:34:32 -04:00
Some("d" | "detach")
=> command::share::detach(&mut state),
Some("h" | "has")
=> command::share::has(&mut state),
2023-04-14 16:38:34 -04:00
2023-04-20 15:31:22 -04:00
Some("l" | "ls" | "list")
=> command::share::list(&state),
2023-04-06 13:34:32 -04:00
2023-04-20 15:31:22 -04:00
Some("n" | "new")
=> command::share::new(&mut state),
2023-04-06 13:34:32 -04:00
2024-06-10 12:03:40 -04:00
Some("p" | "path")
=> command::session::path(&mut state),
2024-03-07 17:10:45 -05:00
Some("s" | "switch")
=> command::session::switch(&mut state),
2024-07-01 09:53:52 -04:00
Some("t" | "title" | "which")
=> command::session::title(state),
2024-03-07 17:10:45 -05:00
2023-04-20 15:31:22 -04:00
_
=> error::no_subcommand(target.unwrap())
2023-04-06 13:34:32 -04:00
}
2024-02-04 16:07:24 -05:00
2023-04-06 13:34:32 -04:00
}