use clap::ArgAction;
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(
name = "rfortune",
version,
about = "Print random quotes from fortune files",
long_about = "rfortune is a Rust implementation of the classic UNIX 'fortune' program.\n\n\
By default, running `rfortune` prints a random quotation from the default file \
(rfortune.dat) stored in your user data directory. Quotes inside a fortune file \
must be separated by a line containing only the '%' character.\n\n\
You can specify a custom fortune file with `--file`, or manage configuration, \
fortune files, and cache using subcommands:\n\n \
• `config init` Create a configuration file with default options.\n \
• `config edit` Edit the configuration file using the system or a chosen editor.\n \
• `file init` Create a sample default fortune file (rfortune.dat).\n \
• `cache clear` Remove all cached last-used fortunes.\n\n\
This makes it easy to test, customize and extend your fortune collections \
while preserving the spirit of the original UNIX command.",
after_help = "EXAMPLES:\n rfortune\n Print a random fortune from the default file (rfortune.dat).\n\n \
rfortune --file ~/fortunes/misc\n Print a random fortune from the file ~/fortunes/misc.\n\n \
rfortune config init\n Create a default configuration file in the user data directory.\n\n \
rfortune config edit\n Open the configuration file in your default system editor.\n\n \
rfortune config edit --editor vi\n Open the configuration file with a specific editor.\n\n \
rfortune file init\n Create a sample fortune file (rfortune.dat) in the user data directory.\n\n \
rfortune cache clear\n Remove all cached last-used fortunes."
)]
pub struct Cli {
#[arg(long = "file", value_name = "FILE", num_args = 1.., action = ArgAction::Append)]
pub files: Option<Vec<String>>,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Config {
#[command(subcommand)]
action: ConfigAction,
},
File {
#[command(subcommand)]
action: FileAction,
},
Cache {
#[command(subcommand)]
action: CacheAction,
},
}
#[derive(Subcommand, Debug)]
pub enum ConfigAction {
Init,
Edit {
#[arg(short, long)]
editor: Option<String>,
},
}
#[derive(Subcommand, Debug)]
pub enum FileAction {
Init,
}
#[derive(Subcommand, Debug)]
pub enum CacheAction {
Clear,
}