This commit is contained in:
naskya 2024-06-21 03:30:05 +09:00
parent df3a9acbfb
commit 939bb1c72f
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
5 changed files with 39 additions and 38 deletions

View file

@ -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,
}

View file

@ -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(())

View file

@ -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(())
}

View file

@ -2,10 +2,10 @@
use color_print::cprintln;
pub(crate) fn run() {
cprintln!("fishctl version: <strong>v{}</>", env!("CARGO_PKG_VERSION"));
pub(super) fn run() {
cprintln!("fishctl version: <bold>v{}</>", env!("CARGO_PKG_VERSION"));
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
);
}

View file

@ -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!("<r!><bold>Error:</></>");