jsona_cli/commands/
mod.rs1#[cfg(feature = "lsp")]
2use self::lsp::LspCommand;
3use self::{format::FormatCommand, lint::LintCommand, queries::GetCommand};
4use crate::App;
5
6mod format;
7mod lint;
8#[cfg(feature = "lsp")]
9mod lsp;
10mod queries;
11
12use clap::{crate_version, ArgEnum, Args, Parser, Subcommand};
13use jsona_util::environment::Environment;
14
15impl<E: Environment> App<E> {
16 pub async fn execute(&mut self, args: AppArgs) -> Result<(), anyhow::Error> {
17 self.colors = match args.colors {
18 Colors::Auto => self.env.atty_stderr(),
19 Colors::Always => true,
20 Colors::Never => false,
21 };
22
23 match args.cmd {
24 JsonaCommand::Format(cmd) => self.execute_format(cmd).await,
25 #[cfg(feature = "lsp")]
26 JsonaCommand::Lsp { cmd } => {
27 #[cfg(feature = "lsp")]
28 {
29 self.execute_lsp(cmd).await
30 }
31 #[cfg(not(feature = "lsp"))]
32 {
33 let _ = cmd;
34 return Err(anyhow::anyhow!("the LSP is not part of this build, please consult the documentation about enabling the functionality"));
35 }
36 }
37 JsonaCommand::Lint(cmd) => self.execute_lint(cmd).await,
38 JsonaCommand::Get(cmd) => self.execute_get(cmd).await,
39 }
40 }
41}
42
43#[derive(Clone, Copy, ArgEnum)]
44pub enum Colors {
45 Auto,
47 Always,
49 Never,
51}
52
53#[derive(Clone, Parser)]
54#[clap(name = "jsona")]
55#[clap(bin_name = "jsona")]
56#[clap(version = crate_version!())]
57pub struct AppArgs {
58 #[clap(long, arg_enum, global = true, default_value = "auto")]
59 pub colors: Colors,
60 #[clap(long, global = true)]
62 pub verbose: bool,
63 #[clap(long, global = true)]
65 pub log_spans: bool,
66 #[clap(subcommand)]
67 pub cmd: JsonaCommand,
68}
69
70#[derive(Debug, Clone, Args)]
71pub struct GeneralArgs {}
72
73#[derive(Clone, Subcommand)]
74pub enum JsonaCommand {
75 #[clap(visible_aliases = &["check", "validate"])]
77 Lint(LintCommand),
78 #[clap(visible_aliases = &["fmt"])]
82 Format(FormatCommand),
83 #[cfg(feature = "lsp")]
85 Lsp {
86 #[clap(subcommand)]
87 cmd: LspCommand,
88 },
89 Get(GetCommand),
91}