Skip to content

Commit 0a4114e

Browse files
committed
imp(flags): make bools true bools
- This affords better help rendering (at the very least)
1 parent efde6ef commit 0a4114e

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can try out this tool easily with `nix run`:
3030

3131
In you want to deploy multiple flakes or a subset of profiles with one invocation, instead of calling `deploy <flake>` you can issue `deploy --targets <flake> [<flake> ...]` where `<flake>` is supposed to take the same format as discussed before.
3232

33-
Running in this mode, if any of the deploys fails, the deploy will be aborted and all successful deploys rolled back. `--rollback-succeeded false` can be used to override this behavior, otherwise the `auto-rollback` argument takes precedent.
33+
Running in this mode, if any of the deploys fails, the deploy will be aborted and all successful deploys rolled back. `--rollback-succeeded false` can be used to override this behavior, otherwise the `no-auto-rollback` argument takes precedent.
3434

3535
If you require a signing key to push closures to your server, specify the path to it in the `LOCAL_KEY` environment variable.
3636

@@ -48,7 +48,7 @@ This type of design (as opposed to more traditional tools like NixOps or morph)
4848

4949
### Magic Rollback
5050

51-
There is a built-in feature to prevent you making changes that might render your machine unconnectable or unusuable, which works by connecting to the machine after profile activation to confirm the machine is still available, and instructing the target node to automatically roll back if it is not confirmed. If you do not disable `magicRollback` in your configuration (see later sections) or with the CLI flag, you will be unable to make changes to the system which will affect you connecting to it (changing SSH port, changing your IP, etc).
51+
There is a built-in feature to prevent you making changes that might render your machine unconnectable or unusuable, which works by connecting to the machine after profile activation to confirm the machine is still available, and instructing the target node to automatically roll back if it is not confirmed. If you do not disable `noMagicRollback` in your configuration (see later sections) or with the CLI flag, you will be unable to make changes to the system which will affect you connecting to it (changing SSH port, changing your IP, etc).
5252

5353
## API
5454

@@ -166,17 +166,15 @@ This is a set of options that can be put in any of the above definitions, with t
166166
# This defaults to `false`
167167
fastConnection = false;
168168
169-
# If the previous profile should be re-activated if activation fails.
170-
# This defaults to `true`
171-
autoRollback = true;
169+
# If the previous profile should NOT be re-activated if activation fails.
170+
noAutoRollback = true;
172171
173-
# See the earlier section about Magic Rollback for more information.
174-
# This defaults to `true`
175-
magicRollback = true;
172+
# See the earlier section about Magic Rollback for more information, disable with this attr.
173+
noMagicRollback = true;
176174
177-
# The path which deploy-rs will use for temporary files, this is currently only used by `magicRollback` to create an inotify watcher in for confirmations
175+
# The path which deploy-rs will use for temporary files, this is currently only used by the magic rollback to create an inotify watcher in for confirmations
178176
# If not specified, this will default to `/tmp`
179-
# (if `magicRollback` is in use, this _must_ be writable by `user`)
177+
# (if magic rollback is in use, this _must_ be writable by `user`)
180178
tempPath = "/home/someuser/.deploy-rs";
181179
}
182180
```

interface.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"fastConnection": {
2222
"type": "boolean"
2323
},
24-
"autoRollback": {
24+
"noAutoRollback": {
2525
"type": "boolean"
2626
},
27-
"magicRollback": {
27+
"noMagicRollback": {
2828
"type": "boolean"
2929
},
3030
"confirmTimeout": {

src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async fn run_deploy(
209209

210210
// Run all deployments
211211
// In case of an error rollback any previoulsy made deployment.
212-
// Rollbacks adhere to the global seeting to auto_rollback and secondary
212+
// Rollbacks adhere to the global seeting to no_auto_rollback and secondary
213213
// the profile's configuration
214214
for deploy_data in &parts {
215215
if let Err(e) = deploy::deploy::deploy_profile(
@@ -226,13 +226,13 @@ async fn run_deploy(
226226
if cmd_flags.dry_activate {
227227
info!("dry run, not rolling back");
228228
}
229-
if cmd_flags.rollback_succeeded && cmd_settings.auto_rollback.unwrap_or(true) {
229+
if cmd_flags.rollback_succeeded && !cmd_settings.no_auto_rollback {
230230
info!("Revoking previous deploys");
231231
// revoking all previous deploys
232232
// (adheres to profile configuration if not set explicitely by
233233
// the command line)
234234
for deploy_data in &succeeded {
235-
if deploy_data.merged_settings.auto_rollback.unwrap_or(true) {
235+
if !deploy_data.merged_settings.no_auto_rollback {
236236
deploy::deploy::revoke(
237237
&deploy_data.node_name,
238238
&deploy_data.profile_name,

src/deploy.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub struct ActivateCommand<'a> {
3535
profile_path: &'a str,
3636
temp_path: &'a str,
3737
closure: &'a str,
38-
auto_rollback: bool,
38+
no_auto_rollback: bool,
3939
confirm_timeout: u16,
40-
magic_rollback: bool,
40+
no_magic_rollback: bool,
4141
debug_logs: bool,
4242
log_dir: Option<&'a str>,
4343
dry_activate: bool,
@@ -50,9 +50,9 @@ impl<'a> ActivateCommand<'a> {
5050
profile_path: &d.profile_path,
5151
temp_path: &d.temp_path,
5252
closure: &d.profile.profile_settings.path,
53-
auto_rollback: d.merged_settings.auto_rollback.unwrap_or(true),
53+
no_auto_rollback: d.merged_settings.no_auto_rollback,
5454
confirm_timeout: d.merged_settings.confirm_timeout.unwrap_or(30),
55-
magic_rollback: d.merged_settings.magic_rollback.unwrap_or(true),
55+
no_magic_rollback: d.merged_settings.no_magic_rollback,
5656
debug_logs: d.flags.debug_logs,
5757
log_dir: d.flags.log_dir.as_deref(),
5858
dry_activate: d.flags.dry_activate,
@@ -77,11 +77,11 @@ impl<'a> ActivateCommand<'a> {
7777

7878
cmd = format!("{} --confirm-timeout {}", cmd, self.confirm_timeout);
7979

80-
if self.magic_rollback {
80+
if !self.no_magic_rollback {
8181
cmd = format!("{} --magic-rollback", cmd);
8282
}
8383

84-
if self.auto_rollback {
84+
if !self.no_auto_rollback {
8585
cmd = format!("{} --auto-rollback", cmd);
8686
}
8787

@@ -102,11 +102,11 @@ fn test_activation_command_builder() {
102102
let sudo = Some("sudo -u test");
103103
let profile_path = "/blah/profiles/test";
104104
let closure = "/nix/store/blah/etc";
105-
let auto_rollback = true;
105+
let no_auto_rollback = false;
106106
let dry_activate = false;
107107
let temp_path = "/tmp";
108108
let confirm_timeout = 30;
109-
let magic_rollback = true;
109+
let no_magic_rollback = false;
110110
let debug_logs = true;
111111
let log_dir = Some("/tmp/something.txt");
112112

@@ -115,10 +115,10 @@ fn test_activation_command_builder() {
115115
sudo,
116116
profile_path,
117117
closure,
118-
auto_rollback,
118+
no_auto_rollback,
119119
temp_path,
120120
confirm_timeout,
121-
magic_rollback,
121+
no_magic_rollback,
122122
debug_logs,
123123
log_dir,
124124
dry_activate
@@ -352,15 +352,15 @@ pub async fn deploy_profile(
352352
);
353353
}
354354
let dry_activate = &activate.dry_activate.clone();
355-
let magic_rollback = &activate.magic_rollback.clone();
355+
let no_magic_rollback = &activate.no_magic_rollback.clone();
356356

357357
let activate_cmd = activate.build();
358358

359359
debug!("Constructed activation command: {}", activate_cmd);
360360

361361
let mut ssh_activate_cmd = ssh.build();
362362

363-
if !*magic_rollback || *dry_activate {
363+
if *no_magic_rollback || *dry_activate {
364364
let ssh_activate_exit_status = ssh_activate_cmd
365365
.arg(activate_cmd)
366366
.status()

src/push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a> CopyCommand<'a> {
105105
pub fn from_data(d: &'a data::DeployData) -> Self {
106106
CopyCommand {
107107
closure: d.profile.profile_settings.path.as_str(),
108-
fast_connection: d.merged_settings.fast_connection.unwrap_or(false),
108+
fast_connection: d.merged_settings.fast_connection,
109109
check_sigs: &d.flags.checksigs,
110110
ssh_uri: d.ssh_uri.as_str(),
111111
ssh_opts: d

src/settings.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ pub struct GenericSettings {
3030
/// Override if the connecting to the target node should be considered fast
3131
#[clap(long)]
3232
#[serde(rename(deserialize = "fastConnection"))]
33-
pub fast_connection: Option<bool>,
34-
/// Override if a rollback should be attempted if activation fails
33+
#[merge(strategy = merge::bool::overwrite_false)]
34+
pub fast_connection: bool,
35+
/// Do not attempt rollback if activation fails
3536
#[clap(long)]
36-
#[serde(rename(deserialize = "autoRollback"))]
37-
pub auto_rollback: Option<bool>,
37+
#[serde(rename(deserialize = "noAutoRollback"))]
38+
#[merge(strategy = merge::bool::overwrite_false)]
39+
pub no_auto_rollback: bool,
3840
/// How long activation should wait for confirmation (if using magic-rollback)
3941
#[clap(long)]
4042
#[serde(rename(deserialize = "confirmTimeout"))]
@@ -43,9 +45,11 @@ pub struct GenericSettings {
4345
#[clap(long)]
4446
#[serde(rename(deserialize = "tempPath"))]
4547
pub temp_path: Option<String>,
48+
/// Do not do a magic rollback (see documentation)
4649
#[clap(long)]
47-
#[serde(rename(deserialize = "magicRollback"))]
48-
pub magic_rollback: Option<bool>,
50+
#[serde(rename(deserialize = "noMagicRollback"))]
51+
#[merge(strategy = merge::bool::overwrite_false)]
52+
pub no_magic_rollback: bool,
4953
}
5054

5155
impl GenericSettings {
@@ -67,7 +71,7 @@ impl GenericSettings {
6771

6872
#[derive(Deserialize, Debug, Clone)]
6973
pub struct NodeSettings {
70-
pub hostname: String,
74+
pub hostname: Option<String>,
7175
pub profiles: HashMap<String, Profile>,
7276
#[serde(
7377
skip_serializing_if = "Vec::is_empty",

0 commit comments

Comments
 (0)