taplo_cli/commands/
mod.rs1use taplo_common::environment::Environment;
2
3use crate::{
4 args::{TaploArgs, TaploCommand},
5 Taplo,
6};
7
8mod config;
9mod format;
10#[cfg(feature = "lint")]
11mod lint;
12#[cfg(feature = "lsp")]
13mod lsp;
14mod queries;
15
16#[cfg(feature = "toml-test")]
17mod toml_test;
18
19impl<E: Environment> Taplo<E> {
20 pub async fn execute(&mut self, taplo: TaploArgs) -> Result<(), anyhow::Error> {
21 self.colors = match taplo.colors {
22 crate::args::Colors::Auto => self.env.atty_stderr(),
23 crate::args::Colors::Always => true,
24 crate::args::Colors::Never => false,
25 };
26
27 match taplo.cmd {
28 #[cfg(feature = "completions")]
29 TaploCommand::Completions { shell } => {
30 use anyhow::anyhow;
31 use clap::CommandFactory;
32 use clap_complete::{generate, shells::Shell};
33 use std::{io::stdout, str::FromStr};
34
35 let shell = Shell::from_str(&shell).map_err(|e| anyhow!(e))?;
36 generate(
37 shell,
38 &mut TaploArgs::command(),
39 TaploArgs::command().get_bin_name().unwrap(),
40 &mut stdout(),
41 );
42 Ok(())
43 }
44 TaploCommand::Config { cmd } => self.execute_config(cmd).await,
45 TaploCommand::Format(fmt) => self.execute_format(fmt).await,
46 TaploCommand::Get(cmd) => self.execute_get(cmd).await,
47 #[cfg(feature = "lint")]
48 TaploCommand::Lint(cmd) => self.execute_lint(cmd).await,
49 #[cfg(feature = "lsp")]
50 TaploCommand::Lsp { cmd } => self.execute_lsp(cmd).await,
51 #[cfg(feature = "toml-test")]
52 TaploCommand::TomlTest {} => self.execute_toml_test().await,
53 }
54 }
55}