wasmtime_cli/commands/
config.rs

1//! The module that implements the `wasmtime config` command.
2
3use anyhow::Result;
4use clap::{Parser, Subcommand};
5
6const CONFIG_NEW_AFTER_HELP: &str =
7    "If no file path is specified, the system configuration file path will be used.";
8
9/// Controls Wasmtime configuration settings
10#[derive(Parser, PartialEq)]
11pub struct ConfigCommand {
12    #[command(subcommand)]
13    subcommand: ConfigSubcommand,
14}
15
16#[derive(Subcommand, PartialEq)]
17enum ConfigSubcommand {
18    /// Creates a new Wasmtime configuration file
19    #[command(after_help = CONFIG_NEW_AFTER_HELP)]
20    New(ConfigNewCommand),
21}
22
23impl ConfigCommand {
24    /// Executes the command.
25    pub fn execute(self) -> Result<()> {
26        match self.subcommand {
27            ConfigSubcommand::New(c) => c.execute(),
28        }
29    }
30}
31
32/// Creates a new Wasmtime configuration file
33#[derive(Parser, PartialEq)]
34pub struct ConfigNewCommand {
35    /// The path of the new configuration file
36    #[arg(index = 1, value_name = "FILE_PATH")]
37    path: Option<String>,
38}
39
40impl ConfigNewCommand {
41    /// Executes the command.
42    pub fn execute(self) -> Result<()> {
43        let path = wasmtime_cache::create_new_config(self.path.as_ref())?;
44
45        println!(
46            "Successfully created a new configuration file at '{}'.",
47            path.display()
48        );
49
50        Ok(())
51    }
52}