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
68
Cargo.lock
generated
68
Cargo.lock
generated
|
|
@ -58,9 +58,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.10"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
|
||||
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
|
|
@ -120,7 +120,7 @@ version = "0.2.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
|
@ -633,7 +633,7 @@ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
|||
|
||||
[[package]]
|
||||
name = "haze"
|
||||
version = "1.6.0"
|
||||
version = "2.1.1"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"atty",
|
||||
|
|
@ -653,12 +653,14 @@ dependencies = [
|
|||
"maplit",
|
||||
"miette",
|
||||
"opener",
|
||||
"owo-colors",
|
||||
"parse-display",
|
||||
"petname",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shell-words",
|
||||
"strum",
|
||||
"tar",
|
||||
"termion",
|
||||
"tokio",
|
||||
|
|
@ -682,6 +684,12 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
|
|
@ -1005,6 +1013,17 @@ version = "2.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "is_ci"
|
||||
version = "1.2.0"
|
||||
|
|
@ -1167,7 +1186,7 @@ dependencies = [
|
|||
"cfg-if",
|
||||
"miette-derive",
|
||||
"owo-colors",
|
||||
"supports-color",
|
||||
"supports-color 3.0.2",
|
||||
"supports-hyperlinks",
|
||||
"supports-unicode",
|
||||
"terminal_size",
|
||||
|
|
@ -1313,9 +1332,13 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "4.2.0"
|
||||
version = "4.2.2"
|
||||
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]]
|
||||
name = "parse-display"
|
||||
|
|
@ -1746,6 +1769,37 @@ dependencies = [
|
|||
"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]]
|
||||
name = "supports-color"
|
||||
version = "3.0.2"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "haze"
|
||||
version = "1.6.0"
|
||||
version = "2.1.1"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2021"
|
||||
repository = "https://github.com/icewind1991/haze"
|
||||
repository = "https://codeberg.org/icewind/haze"
|
||||
license = "MIT"
|
||||
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 }
|
||||
itertools = { version = "0.14.0", features = ["use_alloc"] }
|
||||
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 = "1.6.0"
|
||||
|
|
|
|||
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