-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
79 lines (72 loc) · 2.79 KB
/
cli.rs
File metadata and controls
79 lines (72 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 {
/// Fortune file to use instead of the default (rfortune.dat)
#[arg(short, long)]
pub file: Option<String>,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Manage configuration
Config {
#[command(subcommand)]
action: ConfigAction,
},
/// Manage fortune files
File {
#[command(subcommand)]
action: FileAction,
},
/// Manage cache
Cache {
#[command(subcommand)]
action: CacheAction,
},
}
#[derive(Subcommand, Debug)]
pub enum ConfigAction {
/// Initialize the configuration file
Init,
/// Edit the configuration file with the system or custom editor
Edit {
/// Specify a custom editor name or path
#[arg(short, long)]
editor: Option<String>,
},
}
#[derive(Subcommand, Debug)]
pub enum FileAction {
/// Create a sample default fortune file (rfortune.dat)
Init,
}
#[derive(Subcommand, Debug)]
pub enum CacheAction {
/// Clear the cache directory
Clear,
}