1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
use crate::action;
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "quartz")]
#[command(author = "Eduardo R. <contato@edurodrigues.dev>")]
#[command(about = "Text-based API Client", long_about = None, version)]
pub struct Cli {
/// Run command with given handle
#[arg(short = 'x', value_name = "HANDLE")]
pub from_handle: Option<String>,
/// Apply environment on endpoint as soon as possible. Allows to get resolved information on
/// output
#[arg(short = 'c', long)]
pub apply_environment: bool,
#[command(subcommand)]
pub command: Cmd,
}
#[derive(Debug, Subcommand)]
pub enum Cmd {
/// Initialize quartz
Init(action::init::Args),
/// Send request using the current handle's endpoint and outputs the response
Send(action::send::Args),
/// Create a new handle
Create(action::handle::CreateArgs),
/// Switch handle or edit its endpoint
Use(action::handle::SwitchArgs),
/// Lists available handles
#[command(name = "ls", alias = "list")]
Ls(action::ls::Args),
/// Copy an endpoint from one handle to another
#[command(name = "cp", alias = "copy")]
Cp(action::handle::CpArgs),
/// Move handles
#[command(name = "mv", alias = "move")]
Mv(action::handle::MvArgs),
/// Delete handles
#[command(name = "rm", alias = "remove")]
Rm(action::handle::RmArgs),
/// Print out endpoint informations
Show {
#[command(subcommand)]
command: ShowCmd,
},
/// Open an editor to modify endpoint in use
Edit,
/// Manage current endpoint's query params
Query {
#[command(subcommand)]
command: QueryCmd,
},
/// Manage current endpoint's headers. Without subcomand, it prints the headers list.
#[command(alias = "headers")]
Header {
#[command(subcommand)]
command: HeaderCmd,
},
/// Manage current handle's endpoint request body
Body(action::body::Args),
/// Print information about last request or response
Last {
#[command(subcommand)]
command: Option<LastCmd>,
},
/// Print request history
History(action::history::Args),
/// Manage project's environments
#[command(name = "env", alias = "environment")]
Env {
#[command(subcommand)]
command: EnvCmd,
},
/// Manage current environment's variables
#[command(name = "var", alias = "variable")]
Var {
#[command(subcommand)]
command: VarCmd,
},
/// Manage configuration for quartz
Config {
#[command(subcommand)]
command: ConfigCmd,
},
}
#[derive(Debug, Subcommand)]
pub enum LastCmd {
/// Print most recent handle used
Handle,
/// Print last request information
#[command(name = "req", alias = "request")]
Req,
/// Print last response information
#[command(name = "res", alias = "response")]
Res {
#[command(subcommand)]
command: Option<LastResCmd>,
},
}
#[derive(Debug, Subcommand)]
pub enum LastResCmd {
Head,
Body,
}
#[derive(Debug, Subcommand)]
pub enum QueryCmd {
/// Print query param value
Get(action::query::GetArgs),
/// Set query param value
Set(action::query::SetArgs),
/// Remove query param
#[command(name = "rm", alias = "remove")]
Rm(action::query::RmArgs),
/// List all query params
#[command(name = "ls", alias = "list")]
Ls,
}
#[derive(Debug, Subcommand)]
pub enum HeaderCmd {
/// Print a header value
Get { key: String },
/// Add new or existent header. Expects "key: value" format
Set { header: Vec<String> },
/// Remove a header
#[command(name = "rm", alias = "remove")]
Rm { key: Vec<String> },
/// Print headers
#[command(name = "ls", alias = "list")]
Ls,
}
#[derive(Debug, Subcommand)]
pub enum ShowCmd {
Url,
Method,
/// Display endpoint's headers
Headers {
key: Option<String>,
},
/// Display endpoint's query params
Query {
key: Option<String>,
},
/// Display endpoint's request body
Body,
/// Display current handle
Handle,
/// Display current environment
#[command(name = "env", alias = "environment")]
Env,
/// Display environment cookies
Cookies(action::cookie::PrintArgs),
/// Generate code snippet for endpoint
Snippet(action::snippet::Args),
/// Display endpoint configuration file
Endpoint,
}
#[derive(Debug, Subcommand)]
pub enum SnippetCmd {
Curl(crate::snippet::Curl),
Http,
}
#[derive(Debug, Subcommand)]
pub enum ConfigCmd {
/// Open an editor to modify ~/.quartz.toml
Edit,
/// Print configuration value
Get(action::config::GetArgs),
/// Set a configuration
Set(action::config::SetArgs),
/// Print ~/.quartz.toml
#[command(name = "ls", alias = "list")]
Ls,
}
#[derive(Debug, Subcommand)]
pub enum BodyCmd {
/// Print request body to stdout
Show,
/// Expect a new request body via standard input
Stdin,
/// Open an editor to modify the endpoint's request body
Edit,
}
#[derive(Debug, Subcommand)]
pub enum EnvCmd {
/// Create a new environment
Create(action::env::CreateArgs),
/// Switch to another environment
Use(action::env::SwitchArgs),
/// Print all available environments
#[command(name = "ls", alias = "list")]
Ls,
/// Copy variables from a environment to a new or existing one
#[command(name = "cp", alias = "copy")]
Cp(action::env::CpArgs),
/// Delete a environment
#[command(name = "rm", alias = "remove")]
Rm(action::env::RmArgs),
Header {
#[command(subcommand)]
command: HeaderCmd,
},
}
#[derive(Debug, Subcommand)]
pub enum VarCmd {
/// Open an editor to modify variables
Edit,
/// Display variable value
Get(action::var::GetArgs),
/// Add a new or existent variable value
Set(action::var::SetArgs),
/// Remove variables
Rm(action::var::RmArgs),
/// Display the list of variables
#[command(name = "ls", alias = "list")]
Ls,
}