diff --git a/src/command/config.rs b/src/command/config.rs index 506089a..9ed9f53 100644 --- a/src/command/config.rs +++ b/src/command/config.rs @@ -8,13 +8,13 @@ use clap::{Subcommand, ValueEnum}; #[derive(Subcommand)] pub(crate) enum Commands { /// Convert an old config file into the new format - Migrate { version: ConfigVersion }, + Migrate { version: ConfigRevision }, /// Validate the config file Validate, } #[derive(Clone, ValueEnum)] -pub(crate) enum ConfigVersion { +pub(crate) enum ConfigRevision { #[clap(name = "20240701")] V20240701, } diff --git a/src/command/config/migrate.rs b/src/command/config/migrate.rs index c544835..eb2d5b7 100644 --- a/src/command/config/migrate.rs +++ b/src/command/config/migrate.rs @@ -2,7 +2,7 @@ mod v20240701; -use super::ConfigVersion; +use super::ConfigRevision; #[derive(thiserror::Error, Debug)] pub(crate) enum MigrationError { @@ -10,9 +10,9 @@ pub(crate) enum MigrationError { V20240701(#[from] v20240701::Error), } -pub(super) async fn run(version: ConfigVersion) -> Result<(), MigrationError> { +pub(super) async fn run(version: ConfigRevision) -> Result<(), MigrationError> { match version { - ConfigVersion::V20240701 => v20240701::run().await?, + ConfigRevision::V20240701 => v20240701::run().await?, } Ok(()) diff --git a/src/command/mod.rs b/src/command/mod.rs index 1d57c8f..7e700a6 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,10 +1,38 @@ //! Subcommand implementations -pub(crate) mod config; -pub(crate) mod version; +mod config; +mod version; + +use clap::{Parser, Subcommand}; #[derive(thiserror::Error, Debug)] pub(crate) enum Error { #[error(transparent)] Config(#[from] config::Error), } + +#[derive(Parser)] +struct Args { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + /// Print fishctl version and the corresponding Firefish version + Version, + /// Modify or validate the config files + #[command(subcommand)] + Config(config::Commands), +} + +pub(crate) async fn run() -> Result<(), Error> { + let args = Args::parse(); + + match args.command { + Commands::Version => version::run(), + Commands::Config(subcommand) => config::run(subcommand).await?, + } + + Ok(()) +} diff --git a/src/command/version.rs b/src/command/version.rs index 7e55454..0c9ac19 100644 --- a/src/command/version.rs +++ b/src/command/version.rs @@ -2,10 +2,10 @@ use color_print::cprintln; -pub(crate) fn run() { - cprintln!("fishctl version: v{}", env!("CARGO_PKG_VERSION")); +pub(super) fn run() { + cprintln!("fishctl version: v{}", env!("CARGO_PKG_VERSION")); cprintln!( - "The latest Firefish version as of this fishctl release: v{}", + "The latest Firefish version as of this fishctl release: v{}", crate::FIREFISH_VERSION ); } diff --git a/src/main.rs b/src/main.rs index 6e2292d..49fa69f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,15 @@ mod command; mod config; -use clap::{Parser, Subcommand}; use color_print::cprintln; use std::process::ExitCode; /// latest Firefish version as of this fishctl release const FIREFISH_VERSION: &str = "20240613"; -#[derive(Parser)] -struct Args { - #[command(subcommand)] - command: Commands, -} - -#[derive(Subcommand)] -enum Commands { - /// Print fishctl version and the corresponding Firefish version - Version, - /// Modify or validate the config files - #[command(subcommand)] - Config(command::config::Commands), -} - -async fn run() -> Result<(), command::Error> { - let args = Args::parse(); - - match args.command { - Commands::Version => command::version::run(), - Commands::Config(subcommand) => command::config::run(subcommand).await?, - } - - Ok(()) -} - #[tokio::main] async fn main() -> ExitCode { - let res = run().await; + let res = command::run().await; if let Err(err) = res { cprintln!("Error:");