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
use std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};
#[derive(Debug, StructOpt)]
pub enum CliSubcommand {
/// Add a new script to config.
Add {
/// The command/script content to be executed.
/// If this argument is not found it will open your $EDITOR for you to enter the script into.
command: Option<String>,
/// The alias or name for the script.
#[structopt(short = "a", long = "alias")]
alias: String,
/// The description for the script.
#[structopt(short = "d", long = "--description")]
description: Option<String>,
/// Set which tags the script belongs to.
#[structopt(short = "t", long = "tag")]
tags: Option<Vec<String>>,
/// Allows to overwrite the existing script
#[structopt(short = "f", long = "force")]
force: bool,
},
/// alias: rm - Remove a script matching alias.
#[structopt(alias = "rm")]
Remove {
/// The alias or name for the script.
alias: String,
},
/// alias: init - Add a config file.
#[structopt(alias = "init")]
ConfigInit,
/// Edit a script matching alias.
Edit {
/// The alias or name for the script.
alias: String,
},
/// Show a script matching alias.
Show {
/// The alias or name for the script.
alias: String,
},
/// Run a script matching alias.
Run {
/// The alias or name for the script.
alias: String,
/// The positional arguments to send to script.
args: Vec<String>,
},
/// alias: ls - List scripts
///
/// Display options are determined by priority in this order:
///
/// 1. List only aliases
///
/// 2. Show full command
///
/// 3. Command display with (cli option)
///
/// 4. Command display with (config option)
#[structopt(alias = "ls")]
List {
/// Only displays aliases of the scripts.
#[structopt(short = "q", long = "list_aliases")]
list_aliases: bool,
/// Display the full command.
#[structopt(short = "l", long = "cmd_full")]
cmd_full: bool,
/// The max number of characters to display from the command.
#[structopt(short = "c", long = "cmd_width")]
cmd_width: Option<usize>,
/// Filter based on tags.
#[structopt(short = "t", long = "tag")]
tags: Option<Vec<String>>,
},
/// alias: cp - Copy existing alias to the new one
#[structopt(alias = "cp")]
Copy {
/// The alias of the script that will be copied.
from_alias: String,
/// The new alias of the copy of the script.
to_alias: String,
},
/// alias: mv, rename - Move/rename existing alias to the new one
#[structopt(aliases = &["mv", "rename"])]
Move {
/// The alias of the script that will be moved.
from_alias: String,
/// The new alias of the script.
to_alias: String,
/// Allows to overwrite the existing script
#[structopt(short = "f", long = "force")]
force: bool,
},
}
#[derive(StructOpt, Debug)]
pub struct CliOpts {
/// The level of verbosity
#[structopt(short = "v", long = "verbose")]
pub verbose: bool,
/// Sets a custom config file.
///
/// DEFAULT PATH is otherwise determined in this order:
///
/// - $PIER_CONFIG_PATH (environment variable if set)
///
/// - pier.toml (in the current directory)
///
/// - $XDG_CONFIG_HOME/pier/config.toml
///
/// - $XDG_CONFIG_HOME/pier/config
///
/// - $XDG_CONFIG_HOME/pier.toml
///
/// - $HOME/.pier.toml
///
/// - $HOME/.pier
///
#[structopt(short = "c", long = "config-file", env = "PIER_CONFIG_PATH")]
pub path: Option<PathBuf>,
}
#[derive(Debug, StructOpt)]
#[structopt(setting = AppSettings::SubcommandsNegateReqs, setting = AppSettings::TrailingVarArg, author)]
/// A simple script management CLI
pub struct Cli {
#[structopt(flatten)]
pub opts: CliOpts,
/// The alias or name for the script.
#[structopt(required_unless = "cmd")]
pub alias: Option<String>,
/// The positional arguments to send to script.
pub args: Vec<String>,
/// Pier subcommands
#[structopt(subcommand)]
pub cmd: Option<CliSubcommand>,
}