quartz_cli/action/
show.rs1use crate::{action, cli::ShowCmd as Cmd, Ctx, QuartzResult, StateField};
2
3pub fn cmd(ctx: &Ctx, command: Cmd) -> QuartzResult {
4 match command {
5 Cmd::Query { key } => {
6 if let Some(key) = key {
7 action::query::get(ctx, key);
8 } else {
9 action::query::print(ctx);
10 }
11 }
12 Cmd::Headers { key } => {
13 if let Some(key) = key {
14 action::header::get(ctx, key)?;
15 } else {
16 action::header::ls(ctx)?;
17 }
18 }
19 Cmd::Url => url(ctx),
20 Cmd::Method => method(ctx),
21 Cmd::Body => action::body::print(ctx),
22 Cmd::Handle => handle(ctx),
23 Cmd::Env => action::env::print(ctx),
24 Cmd::Cookies(args) => action::cookie::print(ctx, args),
25 Cmd::Endpoint => endpoint(ctx)?,
26 Cmd::Snippet(args) => action::snippet::cmd(ctx, args)?,
27 };
28
29 Ok(())
30}
31
32pub fn url(ctx: &Ctx) {
33 let (_, endpoint) = ctx.require_endpoint();
34 println!("{}", endpoint.url);
35}
36
37pub fn method(ctx: &Ctx) {
38 let (_, endpoint) = ctx.require_endpoint();
39 println!("{}", endpoint.method);
40}
41
42pub fn handle(ctx: &Ctx) {
43 if let Ok(endpoint) = ctx.state.get(ctx, StateField::Endpoint) {
44 println!("{}", endpoint);
45 }
46}
47
48pub fn endpoint(ctx: &Ctx) -> QuartzResult {
49 let (_, endpoint) = ctx.require_endpoint();
50
51 println!("{}", endpoint.to_toml()?);
52 Ok(())
53}