2023-04-06 13:34:32 -04:00
|
|
|
|
|
|
|
use pico_args::Arguments;
|
|
|
|
|
|
|
|
mod command;
|
2024-06-10 12:02:02 -04:00
|
|
|
mod env;
|
2023-04-14 16:38:34 -04:00
|
|
|
mod error;
|
2024-03-06 15:54:41 -05:00
|
|
|
mod flag;
|
2024-01-23 16:45:58 -05:00
|
|
|
mod help;
|
2024-06-24 16:32:41 -04:00
|
|
|
mod state;
|
2023-04-06 13:34:32 -04:00
|
|
|
mod util;
|
|
|
|
|
2024-02-04 16:11:32 -05:00
|
|
|
use help::{ help, version };
|
2024-06-24 16:32:41 -04:00
|
|
|
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
|
2024-03-06 15:54:41 -05:00
|
|
|
if args.contains(flag::HELP) {
|
2024-01-23 16:45:58 -05:00
|
|
|
help(&mut args);
|
2023-06-19 12:55:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:54:41 -05:00
|
|
|
if args.contains(flag::VERSION) {
|
2024-02-04 16:11:32 -05:00
|
|
|
version();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-24 16:32:41 -04:00
|
|
|
let mut state = State::new(&mut args);
|
2023-06-19 12:55:45 -04:00
|
|
|
|
2024-06-24 16:32:41 -04:00
|
|
|
let target = state.target();
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2024-02-04 16:07:24 -05:00
|
|
|
// invoke subcommand function
|
2024-06-24 16:32:41 -04:00
|
|
|
match target.as_deref() {
|
2024-06-10 12:02:57 -04:00
|
|
|
Some("help")
|
2024-01-23 16:45:58 -05:00
|
|
|
=> help(&mut args),
|
2024-06-18 11:57:08 -04:00
|
|
|
None
|
2024-06-24 16:32:41 -04:00
|
|
|
=> command::share::context_action(&state),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
Some("a" | "attach")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> command::share::attach(&mut state),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-05-01 10:50:47 -04:00
|
|
|
Some("d" | "detach")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> command::share::detach(&mut state),
|
2023-05-01 10:50:47 -04:00
|
|
|
|
2024-06-10 12:02:57 -04:00
|
|
|
Some("h" | "has")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> 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")
|
2024-07-01 09:12:38 -04:00
|
|
|
=> command::share::list(&state),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
Some("n" | "new")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> command::share::new(&mut state),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2024-06-10 12:03:40 -04:00
|
|
|
Some("p" | "path")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> command::session::path(&mut state),
|
2024-06-10 12:01:15 -04:00
|
|
|
|
2024-03-07 17:10:45 -05:00
|
|
|
Some("s" | "switch")
|
2024-06-24 16:32:41 -04:00
|
|
|
=> 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
|
|
|
_
|
2024-06-24 16:32:41 -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
|
|
|
}
|
|
|
|
|