1
0
Fork 0
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:
Robin Appelman 2025-09-01 16:55:58 +02:00
commit e189b2e4f2
5 changed files with 188 additions and 86 deletions

68
Cargo.lock generated
View file

@ -58,9 +58,9 @@ dependencies = [
[[package]] [[package]]
name = "anstyle" name = "anstyle"
version = "1.0.10" version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]] [[package]]
name = "anstyle-parse" name = "anstyle-parse"
@ -120,7 +120,7 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi 0.1.19",
"libc", "libc",
"winapi", "winapi",
] ]
@ -633,7 +633,7 @@ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]] [[package]]
name = "haze" name = "haze"
version = "1.6.0" version = "2.1.1"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"atty", "atty",
@ -653,12 +653,14 @@ dependencies = [
"maplit", "maplit",
"miette", "miette",
"opener", "opener",
"owo-colors",
"parse-display", "parse-display",
"petname", "petname",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
"shell-words", "shell-words",
"strum",
"tar", "tar",
"termion", "termion",
"tokio", "tokio",
@ -682,6 +684,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hermit-abi"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
[[package]] [[package]]
name = "hex" name = "hex"
version = "0.4.3" version = "0.4.3"
@ -1005,6 +1013,17 @@ version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
[[package]]
name = "is-terminal"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [
"hermit-abi 0.5.2",
"libc",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "is_ci" name = "is_ci"
version = "1.2.0" version = "1.2.0"
@ -1167,7 +1186,7 @@ dependencies = [
"cfg-if", "cfg-if",
"miette-derive", "miette-derive",
"owo-colors", "owo-colors",
"supports-color", "supports-color 3.0.2",
"supports-hyperlinks", "supports-hyperlinks",
"supports-unicode", "supports-unicode",
"terminal_size", "terminal_size",
@ -1313,9 +1332,13 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "4.2.0" version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564" checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
dependencies = [
"supports-color 2.1.0",
"supports-color 3.0.2",
]
[[package]] [[package]]
name = "parse-display" name = "parse-display"
@ -1746,6 +1769,37 @@ dependencies = [
"syn 2.0.99", "syn 2.0.99",
] ]
[[package]]
name = "strum"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.99",
]
[[package]]
name = "supports-color"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89"
dependencies = [
"is-terminal",
"is_ci",
]
[[package]] [[package]]
name = "supports-color" name = "supports-color"
version = "3.0.2" version = "3.0.2"

View file

@ -1,9 +1,9 @@
[package] [package]
name = "haze" name = "haze"
version = "1.6.0" version = "2.1.1"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2021" edition = "2021"
repository = "https://github.com/icewind1991/haze" repository = "https://codeberg.org/icewind/haze"
license = "MIT" license = "MIT"
description = "Easy setup and management of Nextcloud test instances using docker" description = "Easy setup and management of Nextcloud test instances using docker"
@ -34,6 +34,8 @@ atty = "0.2.14"
git2 = { version = "0.20.0", default-features = false } git2 = { version = "0.20.0", default-features = false }
itertools = { version = "0.14.0", features = ["use_alloc"] } itertools = { version = "0.14.0", features = ["use_alloc"] }
local-ip-address = "0.6.5" local-ip-address = "0.6.5"
strum = { version = "0.27.2", features = ["derive"] }
owo-colors = { version = "4.2.2", features = ["supports-colors"] }
hyper-reverse-proxy = { version = "0.5.2-dev", git = "https://github.com/chpio/hyper-reverse-proxy", rev = "6934877eb74465204f605cc1c05ca5a9772db7c0" } hyper-reverse-proxy = { version = "0.5.2-dev", git = "https://github.com/chpio/hyper-reverse-proxy", rev = "6934877eb74465204f605cc1c05ca5a9772db7c0" }
hyper = "1.6.0" hyper = "1.6.0"

View file

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

44
src/help.rs Normal file
View 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>()
},
);
}
}

View file

@ -6,6 +6,7 @@ use crate::config::HazeConfig;
use crate::database::DatabaseFamily; use crate::database::DatabaseFamily;
use crate::exec::container_logs; use crate::exec::container_logs;
use crate::git::checkout_all; use crate::git::checkout_all;
use crate::help::help;
use crate::image::update_image; use crate::image::update_image;
use crate::network::clear_networks; use crate::network::clear_networks;
use crate::php::PhpVersion; use crate::php::PhpVersion;
@ -27,6 +28,7 @@ mod config;
mod database; mod database;
mod exec; mod exec;
mod git; mod git;
mod help;
mod image; mod image;
mod mapping; mod mapping;
mod network; mod network;
@ -443,6 +445,13 @@ async fn main() -> Result<ExitCode> {
update_image(&docker, php.image()).await?; 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) Ok(ExitCode::SUCCESS)