1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

version and help

This commit is contained in:
Robin Appelman 2025-09-01 16:55:58 +02:00
commit e189b2e4f2
5 changed files with 188 additions and 86 deletions

View file

@ -5,76 +5,77 @@ use miette::{IntoDiagnostic, Report, Result};
use parse_display::Display;
use std::fmt::Display;
use std::str::FromStr;
use strum::{EnumIter, EnumMessage, EnumString, IntoStaticStr};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum HazeArgs {
/// List all instances
List { filter: Option<String> },
/// Start a new instance
Start { options: CloudOptions },
/// Stop an instance
Stop { filter: Option<String> },
/// Run tests in a new instance
List {
filter: Option<String>,
},
Start {
options: CloudOptions,
},
Stop {
filter: Option<String>,
},
Test {
options: CloudOptions,
args: Vec<String>,
},
/// Run a command in an instance
Exec {
filter: Option<String>,
service: Option<ExecService>,
command: Vec<String>,
},
/// Run an occ command in an instance
Occ {
filter: Option<String>,
command: Vec<String>,
},
/// Connect to the database of an instance
Db {
filter: Option<String>,
root: bool,
command: Vec<String>,
index: Option<String>,
},
/// Remove all non-pinned instances
Clean,
/// View the logs from an instance or service
Logs {
filter: Option<String>,
follow: bool,
service: Option<LogService>,
count: Option<usize>,
},
/// Open an instance in the browser
Open { filter: Option<String> },
/// Run code formatting from a new instance
Fmt { path: String },
/// Run integration tests in a new instance
Open {
filter: Option<String>,
},
Fmt {
path: String,
},
Integration {
options: CloudOptions,
args: Vec<String>,
},
/// Start a shell in an empirical instance
Shell {
options: CloudOptions,
command: Vec<String>,
},
/// Pin an instance
Pin { filter: Option<String> },
/// Unpin an instance
Unpin { filter: Option<String> },
/// Start the proxy
Pin {
filter: Option<String>,
},
Unpin {
filter: Option<String>,
},
Proxy,
/// Checkout a branch in all apps
Checkout { branch: String },
Checkout {
branch: String,
},
Env {
filter: Option<String>,
command: String,
args: Vec<String>,
},
/// Update docker images
Update,
Help,
Version,
}
#[derive(Debug, Clone, Eq, PartialEq)]
@ -121,7 +122,7 @@ impl HazeArgs {
Ok(cmd) => (cmd, None),
Err(_) => {
let cmd = match args.next() {
Some(cmd) => HazeCommand::from_str(cmd.as_ref())?,
Some(cmd) => HazeCommand::from_str(cmd.as_ref()).into_diagnostic()?,
None => {
return Ok(HazeArgs::List {
filter: Some(command_or_filter.into()),
@ -269,85 +270,77 @@ impl HazeArgs {
})
}
HazeCommand::Update => Ok(HazeArgs::Update),
HazeCommand::Help => Ok(HazeArgs::Help),
HazeCommand::Version => Ok(HazeArgs::Version),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Display)]
#[derive(
Debug, Clone, Copy, Eq, PartialEq, Display, IntoStaticStr, EnumIter, EnumString, EnumMessage,
)]
#[strum(serialize_all = "lowercase")]
pub enum HazeCommand {
/// List all instances
List,
/// Start a new instance
Start,
/// Stop an instance
Stop,
/// Run tests in a new instance
Test,
/// Run a command in an instance
Exec,
/// Run an occ command in an instance
Occ,
/// Connect to the database of an instance
Db,
/// Remove all non-pinned instances
Clean,
/// View the logs from an instance or service
Logs,
/// Open an instance in the browser
Open,
/// Run code formatting from a new instance
Fmt,
/// Run integration tests in a new instance
Integration,
/// Start a shell in an empirical instance
Shell,
/// Pin an instance
Pin,
/// Unpin an instance
Unpin,
/// Start the proxy
Proxy,
/// Checkout a branch in all apps
Checkout,
/// Run command with notify_push environment variables
Env,
/// Update docker images
Update,
}
impl FromStr for HazeCommand {
type Err = Report;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"list" => Ok(HazeCommand::List),
"start" => Ok(HazeCommand::Start),
"stop" => Ok(HazeCommand::Stop),
"test" => Ok(HazeCommand::Test),
"exec" => Ok(HazeCommand::Exec),
"occ" => Ok(HazeCommand::Occ),
"db" => Ok(HazeCommand::Db),
"clean" => Ok(HazeCommand::Clean),
"logs" => Ok(HazeCommand::Logs),
"open" => Ok(HazeCommand::Open),
"fmt" => Ok(HazeCommand::Fmt),
"format" => Ok(HazeCommand::Fmt),
"integration" => Ok(HazeCommand::Integration),
"shell" => Ok(HazeCommand::Shell),
"pin" => Ok(HazeCommand::Pin),
"unpin" => Ok(HazeCommand::Unpin),
"proxy" => Ok(HazeCommand::Proxy),
"checkout" => Ok(HazeCommand::Checkout),
"env" => Ok(HazeCommand::Env),
"update" => Ok(HazeCommand::Update),
_ => Err(Report::msg(format!("Unknown command: {}", s))),
}
}
/// Show help text
#[strum(serialize = "help", serialize = "--help")]
Help,
/// Show version number
#[strum(serialize = "version", serialize = "--version")]
Version,
}
impl HazeCommand {
pub fn allows_filter(&self) -> bool {
match self {
HazeCommand::List => true,
HazeCommand::Start => false,
HazeCommand::Stop => true,
HazeCommand::Test => false,
HazeCommand::Exec => true,
HazeCommand::Occ => true,
HazeCommand::Db => true,
HazeCommand::Clean => false,
HazeCommand::Logs => true,
HazeCommand::Open => true,
HazeCommand::Fmt => false,
HazeCommand::Integration => false,
HazeCommand::Shell => false,
HazeCommand::Pin => true,
HazeCommand::Unpin => true,
HazeCommand::Proxy => false,
HazeCommand::Checkout => false,
HazeCommand::Env => true,
HazeCommand::Update => false,
HazeCommand::List
| HazeCommand::Stop
| HazeCommand::Exec
| HazeCommand::Occ
| HazeCommand::Db
| HazeCommand::Logs
| HazeCommand::Open
| HazeCommand::Pin
| HazeCommand::Unpin
| HazeCommand::Env => true,
_ => false,
}
}
}