Organize the public CLI with clap
This commit is contained in:
parent
e7dd95aea6
commit
d08d931b5f
1 changed files with 445 additions and 255 deletions
|
|
@ -7,29 +7,27 @@ fn main() {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if arguments.first().and_then(|value| value.to_str()) == Some("state") {
|
||||
match lazaret_client::state::run_command(&arguments[1..]) {
|
||||
Ok(status) => std::process::exit(status),
|
||||
Err(error) => {
|
||||
eprintln!("Lazaret state maintenance failed: {error}");
|
||||
std::process::exit(1);
|
||||
let current_workspace = std::env::current_dir().unwrap_or_else(|error| {
|
||||
eprintln!("cannot determine current workspace: {error}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
let command = lazaret_client::cli::parse(arguments, current_workspace)
|
||||
.unwrap_or_else(|error| error.exit());
|
||||
match command {
|
||||
lazaret_client::cli::Command::State(command) => {
|
||||
match lazaret_client::state::run_command(command) {
|
||||
Ok(status) => std::process::exit(status),
|
||||
Err(error) => {
|
||||
eprintln!("Lazaret state maintenance failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
lazaret_client::cli::Command::Run(command) => run(&command),
|
||||
}
|
||||
let current_workspace = match std::env::current_dir() {
|
||||
Ok(path) => path,
|
||||
Err(error) => {
|
||||
eprintln!("cannot determine current workspace: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
let command = match lazaret_client::parse_command_line(arguments, current_workspace) {
|
||||
Ok(command) => command,
|
||||
Err(error) => {
|
||||
eprintln!("invalid command line: {error}");
|
||||
std::process::exit(2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn run(command: &lazaret_client::ClientCommand) {
|
||||
let mut backend = match lazaret_client::coordinator_backend::CoordinatorClientBackend::new() {
|
||||
Ok(backend) => backend,
|
||||
Err(error) => {
|
||||
|
|
@ -39,7 +37,7 @@ fn main() {
|
|||
};
|
||||
match lazaret_client::run(
|
||||
&mut backend,
|
||||
&command,
|
||||
command,
|
||||
&mut std::io::stdout(),
|
||||
&mut std::io::stderr(),
|
||||
) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue