mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
command help
This commit is contained in:
parent
e189b2e4f2
commit
f928547ac2
6 changed files with 350 additions and 106 deletions
81
src/args.rs
81
src/args.rs
|
|
@ -2,10 +2,9 @@ use crate::cloud::CloudOptions;
|
|||
use crate::config::{HazeConfig, Preset};
|
||||
use crate::service::{Service, ServiceTrait};
|
||||
use miette::{IntoDiagnostic, Report, Result};
|
||||
use parse_display::Display;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use strum::{EnumIter, EnumMessage, EnumString, IntoStaticStr};
|
||||
use strum::{Display, EnumIter, EnumMessage, EnumProperty, EnumString, IntoStaticStr};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum HazeArgs {
|
||||
|
|
@ -74,7 +73,9 @@ pub enum HazeArgs {
|
|||
args: Vec<String>,
|
||||
},
|
||||
Update,
|
||||
Help,
|
||||
Help {
|
||||
command: Option<HazeCommand>,
|
||||
},
|
||||
Version,
|
||||
}
|
||||
|
||||
|
|
@ -270,42 +271,79 @@ impl HazeArgs {
|
|||
})
|
||||
}
|
||||
HazeCommand::Update => Ok(HazeArgs::Update),
|
||||
HazeCommand::Help => Ok(HazeArgs::Help),
|
||||
HazeCommand::Help => {
|
||||
let command = args.next();
|
||||
let command = command
|
||||
.as_ref()
|
||||
.map(|s| s.as_ref())
|
||||
.map(HazeCommand::from_str)
|
||||
.transpose()
|
||||
.map_err(|_| Report::msg("Unknown command"))?;
|
||||
Ok(HazeArgs::Help { command })
|
||||
}
|
||||
HazeCommand::Version => Ok(HazeArgs::Version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Copy, Eq, PartialEq, Display, IntoStaticStr, EnumIter, EnumString, EnumMessage,
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Display,
|
||||
IntoStaticStr,
|
||||
EnumIter,
|
||||
EnumString,
|
||||
EnumMessage,
|
||||
EnumProperty,
|
||||
)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum HazeCommand {
|
||||
/// List all instances
|
||||
List,
|
||||
/// Start a new instance
|
||||
#[strum(props(InstanceArgs = true))]
|
||||
Start,
|
||||
/// Stop an instance
|
||||
Stop,
|
||||
/// Run tests in a new instance
|
||||
#[strum(props(
|
||||
InstanceArgs = true,
|
||||
Args = "[phpunit arguments] arguments to pass to phpunit"
|
||||
))]
|
||||
Test,
|
||||
/// Run a command in an instance
|
||||
#[strum(props(
|
||||
Args = "[service] run command on a service container instead [command] command to run"
|
||||
))]
|
||||
Exec,
|
||||
/// Run an occ command in an instance
|
||||
#[strum(props(Args = "[occ arguments] arguments to pass to occ"))]
|
||||
Occ,
|
||||
/// Connect to the database of an instance
|
||||
#[strum(props(
|
||||
Args = "[root] connect to the database as root [db index] database instance to use for sharded setup [sql] sql command to run"
|
||||
))]
|
||||
Db,
|
||||
/// Remove all non-pinned instances
|
||||
Clean,
|
||||
/// View the logs from an instance or service
|
||||
#[strum(props(
|
||||
Args = "[service] service to show logs from [follow] show logs lines as they appear [count] number of lines to show"
|
||||
))]
|
||||
Logs,
|
||||
/// Open an instance in the browser
|
||||
Open,
|
||||
/// Run code formatting from a new instance
|
||||
#[strum(props(Args = "[path] path to format"))]
|
||||
Fmt,
|
||||
/// Run integration tests in a new instance
|
||||
#[strum(props(InstanceArgs = true, Args = "[args] arguments to pass to behat"))]
|
||||
Integration,
|
||||
/// Start a shell in an empirical instance
|
||||
#[strum(props(InstanceArgs = true, Args = "[command] command to run"))]
|
||||
Shell,
|
||||
/// Pin an instance
|
||||
Pin,
|
||||
|
|
@ -314,34 +352,39 @@ pub enum HazeCommand {
|
|||
/// Start the proxy
|
||||
Proxy,
|
||||
/// Checkout a branch in all apps
|
||||
///
|
||||
/// Only switches branches if the target branch exists locally.
|
||||
/// "main" and "master" can be used interchangeably.
|
||||
#[strum(props(Args = "[branch] branch to checkout"))]
|
||||
Checkout,
|
||||
/// Run command with notify_push environment variables
|
||||
Env,
|
||||
#[strum(props(Args = "[command] command to run with environment variables"))]
|
||||
/// Update docker images
|
||||
Update,
|
||||
/// Show help text
|
||||
#[strum(serialize = "help", serialize = "--help")]
|
||||
#[strum(serialize = "--help", to_string = "help")]
|
||||
Help,
|
||||
/// Show version number
|
||||
#[strum(serialize = "version", serialize = "--version")]
|
||||
#[strum(serialize = "--version", to_string = "version")]
|
||||
Version,
|
||||
}
|
||||
|
||||
impl HazeCommand {
|
||||
pub fn allows_filter(&self) -> bool {
|
||||
match self {
|
||||
matches!(
|
||||
self,
|
||||
HazeCommand::List
|
||||
| HazeCommand::Stop
|
||||
| HazeCommand::Exec
|
||||
| HazeCommand::Occ
|
||||
| HazeCommand::Db
|
||||
| HazeCommand::Logs
|
||||
| HazeCommand::Open
|
||||
| HazeCommand::Pin
|
||||
| HazeCommand::Unpin
|
||||
| HazeCommand::Env => true,
|
||||
_ => false,
|
||||
}
|
||||
| HazeCommand::Stop
|
||||
| HazeCommand::Exec
|
||||
| HazeCommand::Occ
|
||||
| HazeCommand::Db
|
||||
| HazeCommand::Logs
|
||||
| HazeCommand::Open
|
||||
| HazeCommand::Pin
|
||||
| HazeCommand::Unpin
|
||||
| HazeCommand::Env
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue