taplo_cli/commands/
mod.rs

1use taplo_common::environment::Environment;
2
3use crate::{
4    args::{TaploArgs, TaploCommand},
5    Taplo,
6};
7
8mod config;
9mod format;
10mod lint;
11#[cfg(feature = "lsp")]
12mod lsp;
13mod queries;
14
15#[cfg(feature = "toml-test")]
16mod toml_test;
17
18impl<E: Environment> Taplo<E> {
19    pub async fn execute(&mut self, taplo: TaploArgs) -> Result<(), anyhow::Error> {
20        self.colors = match taplo.colors {
21            crate::args::Colors::Auto => self.env.atty_stderr(),
22            crate::args::Colors::Always => true,
23            crate::args::Colors::Never => false,
24        };
25
26        match taplo.cmd {
27            TaploCommand::Format(fmt) => self.execute_format(fmt).await,
28            TaploCommand::Lsp { cmd } => {
29                #[cfg(feature = "lsp")]
30                {
31                    self.execute_lsp(cmd).await
32                }
33                #[cfg(not(feature = "lsp"))]
34                {
35                    let _ = cmd;
36                    Err(anyhow::anyhow!("the LSP is not part of this build, please consult the documentation about enabling the functionality"))
37                }
38            }
39
40            #[cfg(feature = "toml-test")]
41            TaploCommand::TomlTest {} => self.execute_toml_test().await,
42            TaploCommand::Lint(cmd) => self.execute_lint(cmd).await,
43            TaploCommand::Config { cmd } => self.execute_config(cmd).await,
44            TaploCommand::Get(cmd) => self.execute_get(cmd).await,
45        }
46    }
47}