use anyhow::Result;
use clap::Parser;
const CONFIG_NEW_AFTER_HELP: &str =
"If no file path is specified, the system configuration file path will be used.";
#[derive(Parser)]
#[clap(name = "config")]
pub struct ConfigCommand {
#[clap(subcommand)]
subcommand: ConfigSubcommand,
}
#[derive(clap::Subcommand)]
enum ConfigSubcommand {
#[clap(after_help = CONFIG_NEW_AFTER_HELP)]
New(ConfigNewCommand),
}
impl ConfigCommand {
pub fn execute(self) -> Result<()> {
match self.subcommand {
ConfigSubcommand::New(c) => c.execute(),
}
}
}
#[derive(Parser)]
#[clap(name = "new", after_help = CONFIG_NEW_AFTER_HELP)]
pub struct ConfigNewCommand {
#[clap(index = 1, value_name = "FILE_PATH")]
path: Option<String>,
}
impl ConfigNewCommand {
pub fn execute(self) -> Result<()> {
let path = wasmtime_cache::create_new_config(self.path.as_ref())?;
println!(
"Successfully created a new configuration file at '{}'.",
path.display()
);
Ok(())
}
}