-
Notifications
You must be signed in to change notification settings - Fork 16
/
cli.rs
181 lines (173 loc) · 5.4 KB
/
cli.rs
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//! `StructOpt` data
use std::path::PathBuf;
use structopt::clap::AppSettings;
use structopt::clap::Shell;
use structopt::StructOpt;
use crate::configuration::ConfigCommand;
use crate::the_way::filter::Filters;
#[derive(Debug, StructOpt)]
#[structopt(
name = "the-way",
rename_all = "kebab-case",
global_settings = & [AppSettings::DeriveDisplayOrder]
)]
/// Record, retrieve, search, and categorize code snippets
pub struct TheWayCLI {
/// Force colorization even when not in TTY mode
#[structopt(short, long)]
pub colorize: bool,
/// Turn off colorization
#[structopt(short, long, conflicts_with = "colorize")]
pub plain: bool,
#[structopt(subcommand)]
pub cmd: TheWaySubcommand,
}
#[derive(Debug, StructOpt)]
/// Record, retrieve, search, and categorize code snippets
pub enum TheWaySubcommand {
/// Add a new code snippet
New,
/// Add a new shell snippet
Cmd {
/// shell snippet code
code: Option<String>,
},
/// Fuzzy search to find a snippet and copy, edit or delete it
Search {
#[structopt(flatten)]
filters: Filters,
/// Print to stdout instead of copying (with Enter)
#[structopt(long, short)]
stdout: bool,
/// Use exact search instead of fuzzy
#[structopt(long, short)]
exact: bool,
},
/// Sync snippets to a Gist
///
/// Controlled by $THE_WAY_GITHUB_TOKEN env variable.
/// Set this to an access token with the "gist" scope obtained from https://github.com/settings/tokens/new
Sync {
#[structopt(subcommand)]
cmd: SyncCommand,
/// Don't ask for confirmation before deleting local snippets
#[structopt(long, short)]
force: bool,
},
/// Lists (optionally filtered) snippets
List {
#[structopt(flatten)]
filters: Filters,
},
/// Imports code snippets from JSON.
///
/// Looks for description, language, and code fields.
Import {
/// filename, reads from stdin if not given
#[structopt(parse(from_os_str))]
file: Option<PathBuf>,
/// URL to a Gist, if provided will import snippets from given Gist
///
/// Multiple files will be converted to separate snippets.
/// Snippet description is created based on Gist description and file name with the format
/// "<gist_description> - <gist_id> - <file_name>".
/// Each snippet will be tagged with "gist" and its Gist ID.
/// Works for both secret and public gists.
#[structopt(long, short)]
gist_url: Option<String>,
/// URL to a gist file produced by `the-way sync`. If provided will import snippets with
/// descriptions and tags taken from the `index.md` index file in the gist.
#[structopt(long, short = "w", conflicts_with = "gist-url")]
the_way_url: Option<String>,
},
/// Saves (optionally filtered) snippets to JSON.
Export {
/// filename, writes to stdout if not given
#[structopt(parse(from_os_str))]
file: Option<PathBuf>,
#[structopt(flatten)]
filters: Filters,
},
/// Clears all data
Clear {
/// Don't ask for confirmation
#[structopt(long, short)]
force: bool,
},
/// Generate shell completions
Complete {
/// Shell to generate completions for
#[structopt(possible_values = & Shell::variants())]
shell: Shell,
},
/// Manage syntax highlighting themes
Themes {
#[structopt(subcommand)]
cmd: ThemeCommand,
},
/// Manage the-way data locations.
///
/// Controlled by $THE_WAY_CONFIG env variable,
/// use this to have independent snippet sources for different projects.
#[structopt(alias = "configure")]
Config {
#[structopt(subcommand)]
cmd: ConfigCommand,
},
/// Change snippet
Edit {
/// Index of snippet to change
index: usize,
},
/// Delete snippet
#[structopt(alias = "delete")]
Del {
/// Index of snippet to delete
index: usize,
/// Don't ask for confirmation
#[structopt(long, short)]
force: bool,
},
/// Copy snippet to clipboard
#[structopt(alias = "copy")]
Cp {
/// Index of snippet to copy
index: usize,
/// Print to stdout instead of copying
#[structopt(long, short)]
stdout: bool,
},
/// View snippet
View {
/// Index of snippet to show
index: usize,
},
}
#[derive(StructOpt, Debug)]
pub enum ThemeCommand {
/// Set your preferred syntax highlighting theme
Set { theme: Option<String> },
/// Add a theme from a Sublime Text ".tmTheme" file.
Add {
/// .tmTheme file path
#[structopt(parse(from_os_str))]
file: PathBuf,
},
/// Add highlight support for a language using a ".sublime-syntax" file.
Language {
/// .sublime-syntax file path
#[structopt(parse(from_os_str))]
file: PathBuf,
},
/// Prints the current theme name
Get,
}
#[derive(StructOpt, Debug, Eq, PartialEq)]
pub enum SyncCommand {
/// Sync by comparing each snippet's updated date to Gist updated date
Date,
/// Use local snippets as source of truth, choose this after upgrading to a new release or if Gist is messed up
Local,
/// Use Gist snippets as source of truth, choose this to sync snippets across computers
Gist,
}