-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparameters.rs
More file actions
169 lines (134 loc) · 5.48 KB
/
parameters.rs
File metadata and controls
169 lines (134 loc) · 5.48 KB
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
use clap::{CommandFactory, Parser};
use std::{env, io};
use clap_complete::{generate, Shell};
use std::process::exit;
#[derive(Parser, Debug)]
#[command(author, version,
about = "convenient management and execution of command on groups of hosts",
after_help = r###"
EXAMPLES
Show disk usage on all systems which belong to group 'foobar'
"hostctl -c 'df -h' foobar"
Show disk usage on all systems which belong to group 'foobar', ask after
every node what to do next
"hostctl -p -c 'df -h' foobar"
Execute ncurses application 'top' on all systems which belong to group
'foobar' using a pseudo tty
"hostctl -t -c 'top' foobar"
Copy files using rsync to a remotehost by replacing the string HOST with the
current hostname of the systems
"hostctl -e -c 'rsync -avP /tmp/foo HOST:/tmp/bar' foobar"
Execute script/recipe 'apache_status' on all systems which belong to
group 'foobar' (shortcut or explictit path)
"hostctl -r apache_status foobar"
"hostctl -r /foo/bar/baz/apache_status foobar"
Login sequentially on all hosts which belong to group 'foobar'
"hostctl -l foobar"
Start a screen session with 'top' on all systems which belong to group
'foobar'
"hostctl -c 'top' --inscreen my-magic-screen foobar"
"screen -x my-magic-screen"
ENVIRONMENT VARIABLES
HOSTCTL_CONFIG
Define a alternate configuration location directory
Default search order: ~/.hostctl/hostctl.conf, <HOSTCTL BINARY DIRECTORY>/hostctl.conf
"###
)]
pub struct CommandLineArgs {
/// Command to execute. A ssh login is performed on the specified hosts and the specified
/// command is executed on the remotehost.
#[arg(short, long, default_value = "")]
pub(crate) command: String,
/// Execute as local command and add hostname to the command
/// (Hostname will be appended to the command, or inserted where 'HOST' string
/// is located in the string.
#[arg(short, long)]
pub(crate) execute_local: bool,
/// Recipe to execute. A recipe is a shellscript which defines recurring administration tasks.
/// Recipes can be stored in $HOME/.hostctl/recipe/ or <hostctl-installation-path>/recipe/ and can
/// be called by their basename.
/// Alternatively, recipes can be called be their fully qualified path.
#[arg(short, long, default_value = "", value_hint = clap::ValueHint::AnyPath)]
pub(crate) recipe: String,
/// Specify hosts instead of groups.
#[arg(short, long, )]
pub(crate) nodes: bool,
/// show group(s)
#[arg(short, long)]
pub(crate) show: bool,
/// output for shell completion
#[arg(long)]
pub(crate) for_completion: bool,
/// Output an array list od nodes
#[arg(short, long)]
pub(crate) array: bool,
/// output hosts in json format
#[arg(short, long)]
pub(crate) json: bool,
/// debug mode
#[arg(short, long)]
pub(crate) debug: bool,
/// disable automatic detection of interactive usage and output colors always
#[arg(short, long)]
pub(crate) forcecolor: bool,
/// reduce output, useful for aggregating output of multiple hosts
#[arg(short, long)]
pub(crate) quiet: bool,
// batchmode, no password prompting (skip host if not ssh-key auth is possible)
#[arg(short, long)]
pub(crate) batchmode: bool,
/// start command/script screen session
// (screen -x <session>, see 'man screen' or 'STRG+a :help')
#[arg(short, long, default_value = "")]
pub(crate) inscreen: String,
/// Add the arguments to the ssh command.
#[arg(short, long, default_value = "")]
pub(crate) optssh: String,
/// login to each host
/// (sleep 1 second after every login, use STRG+c to terminate iteration)
#[arg(short, long)]
pub(crate) login: bool,
/// use sudo to gather root privileges
#[arg(long)]
pub(crate) sudo: bool,
/// Force pseudo-tty allocation
/// (typically needed for tools which use (ncurses-)text-menus)
#[arg(short, long)]
pub(crate) term: bool,
/// wait a specified number of seconds before continuing at next host
#[arg(short, long, default_value = "0")]
pub(crate) wait: u64,
/// ask after every execution, if hostctl should continue, retry, execute a shell or quit
#[arg(short, long)]
pub(crate) prompt: bool,
/// raise a prompt before each host which provides the possibility to
/// confirm or skip the host or quit execution
#[arg(short, long)]
pub(crate) makeselection: bool,
/// accept all ssh known hosts keys
#[arg(short, long)]
pub(crate) knownhostsaccept: bool,
/// The log level
#[arg(long, default_value = "info")]
pub(crate) log_level: String,
/// Groups or nodes for the iteration
#[arg(value_name = "ITEM")]
pub(crate) items: Vec<String>,
}
pub fn shell_completions(){
if let Some(shell) = env::args().nth(1) {
if shell == "generate-completions" {
if let Some(shell_name) = env::args().nth(2) {
let shell_enum = shell_name.parse::<Shell>();
if let Ok(shell_enum) = shell_enum {
let mut cmd = CommandLineArgs::command();
let bin_name = env!("CARGO_PKG_NAME");
generate(shell_enum, &mut cmd, bin_name, &mut io::stdout());
exit(0);
}
}
eprintln!("Usage: {} generate-completions <shell>", env!("CARGO_PKG_NAME"));
exit(1);
}
}
}