summaryrefslogtreecommitdiff
path: root/src/opt.rs
blob: 4e6f46db53f93609b5c7f270d305589d16a543f5 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Command line options.

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,

    /// Create a new journal in the chosen directory.
    Init {
        #[structopt(help = "Short name for journal")]
        journalname: String,

        #[structopt(help = "Short description of journal, its title")]
        description: String,
    },

    /// Check if a directory is a journal.
    IsJournal,

    /// Create draft for a new journal entry.
    New {
        #[structopt(help = "Title of new draft")]
        title: String,

        #[structopt(long, help = "Add link to a topic page")]
        topic: Option<PathBuf>,
    },

    /// Create topic page.
    NewTopic {
        #[structopt(help = "Path to topic page in journal")]
        path: PathBuf,

        #[structopt(help = "Title of topic page")]
        title: String,
    },

    /// Invoke editor on journal entry draft.
    Edit {
        /// Draft id.
        draft: String,
    },

    /// Finish a journal entry draft.
    Finish {
        /// Draft id.
        draft: String,

        /// Set base name of published file.
        basename: String,
    },
}