summaryrefslogtreecommitdiff
path: root/src/opt.rs
blob: 7d3dcda37aa46959bd77fd59b1344612b68dc657 (plain)
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
//! Command line options.

use crate::cmd;
use std::path::PathBuf;
use structopt::StructOpt;

/// A parsed command line.
#[derive(Debug, StructOpt)]
#[structopt(about = "maintain a journal")]
pub struct Opt {
    /// Global options, common for all subcommands.
    #[structopt(flatten)]
    pub global: GlobalOptions,

    /// The subcommand.
    #[structopt(subcommand)]
    pub cmd: SubCommand,
}

/// Global options.
///
/// These options are common to all subcommands.
#[derive(Debug, StructOpt)]
pub struct GlobalOptions {
    /// Which configuration file to read.
    #[structopt(short, long, help = "Configuration file")]
    pub config: Option<PathBuf>,

    /// Which directory to use for the journal.
    #[structopt(short, long, help = "Directory where journal should be stored")]
    pub dirname: Option<PathBuf>,

    /// Sub-directory in journal where new entries are put.
    #[structopt(long)]
    pub entries: Option<PathBuf>,

    /// Which editor to invoke for editing journal entry drafts.
    #[structopt(
        long,
        short,
        help = "Invoke EDITOR for user to edit draft journal entry"
    )]
    pub editor: Option<String>,
}

/// A subcommand.
#[derive(Debug, StructOpt)]
pub enum SubCommand {
    /// Show configuration.
    Config(cmd::Config),

    /// Create a new journal in the chosen directory.
    Init(cmd::Init),

    /// Check if a directory is a journal.
    IsJournal(cmd::IsJournal),

    /// Create draft for a new journal entry.
    New(cmd::New),

    /// Create topic page.
    NewTopic(cmd::NewTopic),

    /// Invoke editor on journal entry draft.
    Edit(cmd::Edit),

    /// Finish a journal entry draft.
    Finish(cmd::Finish),
}