mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
version and help
This commit is contained in:
parent
85335d84de
commit
e189b2e4f2
5 changed files with 188 additions and 86 deletions
147
src/args.rs
147
src/args.rs
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
src/help.rs
Normal file
44
src/help.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use crate::args::HazeCommand;
|
||||
use owo_colors::colors::xterm::Gray;
|
||||
use owo_colors::OwoColorize;
|
||||
use strum::{EnumMessage, IntoEnumIterator};
|
||||
|
||||
pub fn help() {
|
||||
println!(
|
||||
"{} {} {}",
|
||||
"Usage:".bright_yellow().bold(),
|
||||
"haze".blue(),
|
||||
"[filter] <COMMAND> [arguments]".green()
|
||||
);
|
||||
println!();
|
||||
println!("{}", "Commands:".yellow().bold());
|
||||
let max_command_len = HazeCommand::iter()
|
||||
.map(|command| <&'static str>::from(command).len())
|
||||
.max()
|
||||
.unwrap();
|
||||
let max_doc_len = HazeCommand::iter()
|
||||
.map(|command| command.get_documentation().unwrap_or_default().len())
|
||||
.max()
|
||||
.unwrap();
|
||||
|
||||
for command in HazeCommand::iter() {
|
||||
let command: HazeCommand = command;
|
||||
let command_str = <&'static str>::from(command);
|
||||
let mut len = command_str.len();
|
||||
if command_str.starts_with("--") {
|
||||
len -= 2;
|
||||
}
|
||||
println!(
|
||||
" {}{} {}{} {}",
|
||||
command.blue(),
|
||||
" ".repeat(max_command_len - len),
|
||||
command.get_documentation().unwrap_or_default(),
|
||||
" ".repeat(max_doc_len - command.get_documentation().unwrap_or_default().len()),
|
||||
if command.allows_filter() {
|
||||
"- supports filter".fg::<Gray>()
|
||||
} else {
|
||||
"".fg::<Gray>()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use crate::config::HazeConfig;
|
|||
use crate::database::DatabaseFamily;
|
||||
use crate::exec::container_logs;
|
||||
use crate::git::checkout_all;
|
||||
use crate::help::help;
|
||||
use crate::image::update_image;
|
||||
use crate::network::clear_networks;
|
||||
use crate::php::PhpVersion;
|
||||
|
|
@ -27,6 +28,7 @@ mod config;
|
|||
mod database;
|
||||
mod exec;
|
||||
mod git;
|
||||
mod help;
|
||||
mod image;
|
||||
mod mapping;
|
||||
mod network;
|
||||
|
|
@ -443,6 +445,13 @@ async fn main() -> Result<ExitCode> {
|
|||
update_image(&docker, php.image()).await?;
|
||||
}
|
||||
}
|
||||
HazeArgs::Version => {
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
println!("haze v{}", VERSION);
|
||||
}
|
||||
HazeArgs::Help => {
|
||||
help();
|
||||
}
|
||||
};
|
||||
|
||||
Ok(ExitCode::SUCCESS)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue