refactor
This commit is contained in:
parent
df3a9acbfb
commit
939bb1c72f
5 changed files with 39 additions and 38 deletions
|
@ -8,13 +8,13 @@ use clap::{Subcommand, ValueEnum};
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub(crate) enum Commands {
|
pub(crate) enum Commands {
|
||||||
/// Convert an old config file into the new format
|
/// Convert an old config file into the new format
|
||||||
Migrate { version: ConfigVersion },
|
Migrate { version: ConfigRevision },
|
||||||
/// Validate the config file
|
/// Validate the config file
|
||||||
Validate,
|
Validate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ValueEnum)]
|
#[derive(Clone, ValueEnum)]
|
||||||
pub(crate) enum ConfigVersion {
|
pub(crate) enum ConfigRevision {
|
||||||
#[clap(name = "20240701")]
|
#[clap(name = "20240701")]
|
||||||
V20240701,
|
V20240701,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mod v20240701;
|
mod v20240701;
|
||||||
|
|
||||||
use super::ConfigVersion;
|
use super::ConfigRevision;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub(crate) enum MigrationError {
|
pub(crate) enum MigrationError {
|
||||||
|
@ -10,9 +10,9 @@ pub(crate) enum MigrationError {
|
||||||
V20240701(#[from] v20240701::Error),
|
V20240701(#[from] v20240701::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(version: ConfigVersion) -> Result<(), MigrationError> {
|
pub(super) async fn run(version: ConfigRevision) -> Result<(), MigrationError> {
|
||||||
match version {
|
match version {
|
||||||
ConfigVersion::V20240701 => v20240701::run().await?,
|
ConfigRevision::V20240701 => v20240701::run().await?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,10 +1,38 @@
|
||||||
//! Subcommand implementations
|
//! Subcommand implementations
|
||||||
|
|
||||||
pub(crate) mod config;
|
mod config;
|
||||||
pub(crate) mod version;
|
mod version;
|
||||||
|
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub(crate) enum Error {
|
pub(crate) enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Config(#[from] config::Error),
|
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(())
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
use color_print::cprintln;
|
use color_print::cprintln;
|
||||||
|
|
||||||
pub(crate) fn run() {
|
pub(super) fn run() {
|
||||||
cprintln!("fishctl version: <strong>v{}</>", env!("CARGO_PKG_VERSION"));
|
cprintln!("fishctl version: <bold>v{}</>", env!("CARGO_PKG_VERSION"));
|
||||||
cprintln!(
|
cprintln!(
|
||||||
"The latest Firefish version as of this fishctl release: <strong>v{}</>",
|
"The latest Firefish version as of this fishctl release: <bold>v{}</>",
|
||||||
crate::FIREFISH_VERSION
|
crate::FIREFISH_VERSION
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -1,42 +1,15 @@
|
||||||
mod command;
|
mod command;
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
|
||||||
use color_print::cprintln;
|
use color_print::cprintln;
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
/// latest Firefish version as of this fishctl release
|
/// latest Firefish version as of this fishctl release
|
||||||
const FIREFISH_VERSION: &str = "20240613";
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> ExitCode {
|
async fn main() -> ExitCode {
|
||||||
let res = run().await;
|
let res = command::run().await;
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
cprintln!("<r!><bold>Error:</></>");
|
cprintln!("<r!><bold>Error:</></>");
|
||||||
|
|
Loading…
Reference in a new issue