opt.rs
1 //! Command line options. 2 3 use crate::cmd; 4 use clap::Parser; 5 use std::path::PathBuf; 6 7 /// A parsed command line. 8 #[derive(Debug, Parser)] 9 #[clap(about = "maintain a journal")] 10 pub struct Opt { 11 /// Global options, common for all subcommands. 12 #[clap(flatten)] 13 pub global: GlobalOptions, 14 15 /// The subcommand. 16 #[clap(subcommand)] 17 pub cmd: SubCommand, 18 } 19 20 /// Global options. 21 /// 22 /// These options are common to all subcommands. 23 #[derive(Debug, Parser)] 24 pub struct GlobalOptions { 25 /// Which configuration file to read. 26 #[structopt(short, long, help = "Configuration file")] 27 pub config: Option<PathBuf>, 28 29 /// Which directory to use for the journal. 30 #[structopt(short, long, help = "Directory where journal should be stored")] 31 pub dirname: Option<PathBuf>, 32 33 /// Sub-directory in journal where new entries are put. 34 #[structopt(long)] 35 pub entries: Option<PathBuf>, 36 37 /// Which editor to invoke for editing journal entry drafts. 38 #[structopt( 39 long, 40 short, 41 help = "Invoke EDITOR for user to edit draft journal entry" 42 )] 43 pub editor: Option<String>, 44 } 45 46 /// A subcommand. 47 #[derive(Debug, Parser)] 48 pub enum SubCommand { 49 /// Show configuration. 50 Config(cmd::Config), 51 52 /// Create a new journal in the chosen directory. 53 Init(cmd::Init), 54 55 /// Check if a directory is a journal. 56 IsJournal(cmd::IsJournal), 57 58 /// Create draft for a new journal entry. 59 New(cmd::New), 60 61 /// List current drafts. 62 List(cmd::List), 63 64 /// Create topic page. 65 NewTopic(cmd::NewTopic), 66 67 /// Invoke editor on journal entry draft. 68 Edit(cmd::Edit), 69 70 /// Remove a journal entry draft. 71 Remove(cmd::Remove), 72 73 /// Finish a journal entry draft. 74 Finish(cmd::Finish), 75 }