Skip to content

Commit

Permalink
Groom plan synopsis (#338)
Browse files Browse the repository at this point in the history
* Groom plan synopsis

* Review nits
  • Loading branch information
Hoverbear authored Mar 16, 2023
1 parent 89094e0 commit c55a59b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/action/common/configure_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ impl Action for ConfigureInitService {
vec![ActionDescription::new(
"Unconfigure Nix daemon related settings with systemd".to_string(),
vec![
"Run `systemctl disable {SOCKET_SRC}`".to_string(),
"Run `systemctl disable {SERVICE_SRC}`".to_string(),
format!("Run `systemctl disable {SOCKET_SRC}`"),
format!("Run `systemctl disable {SERVICE_SRC}`"),
"Run `systemd-tempfiles --remove --prefix=/nix/var/nix`".to_string(),
"Run `systemctl daemon-reload`".to_string(),
],
Expand Down
1 change: 1 addition & 0 deletions src/cli/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl CommandExecute for Install {
match interaction::prompt(
install_plan
.describe_uninstall(currently_explaining)
.await
.map_err(|e| eyre!(e))?,
PromptChoice::Yes,
currently_explaining,
Expand Down
1 change: 1 addition & 0 deletions src/cli/subcommand/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl CommandExecute for Uninstall {
loop {
match interaction::prompt(
plan.describe_uninstall(currently_explaining)
.await
.map_err(|e| eyre!(e))?,
PromptChoice::Yes,
currently_explaining,
Expand Down
73 changes: 45 additions & 28 deletions src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ impl InstallPlan {
let buf = format!(
"\
Nix install plan (v{version})\n\
\n\
Planner: {planner}\n\
Planner: {planner}{maybe_default_setting_note}\n\
\n\
{maybe_plan_settings}\
\
The following actions will be taken:\n\
\n\
Planned actions:\n\
{actions}\n\
",
planner = planner.typetag_name(),
maybe_default_setting_note = if plan_settings.is_empty() {
String::from(" (with default settings)")
} else {
String::new()
},
maybe_plan_settings = if plan_settings.is_empty() {
String::new()
} else {
// TODO: "Changed planner settings"?
format!(
"\
Planner settings:\n\
\n\
Configured settings:\n\
{plan_settings}\n\
\n\
",
Expand Down Expand Up @@ -213,39 +213,56 @@ impl InstallPlan {
}

#[tracing::instrument(level = "debug", skip_all)]
pub fn describe_uninstall(&self, explain: bool) -> Result<String, NixInstallerError> {
pub async fn describe_uninstall(&self, explain: bool) -> Result<String, NixInstallerError> {
let Self {
version: _,
version,
planner,
actions,
..
} = self;

let plan_settings = if explain {
// List all settings when explaining
planner.settings()?
} else {
// Otherwise, only list user-configured settings
planner.configured_settings().await?
};
let mut plan_settings = plan_settings
.into_iter()
.map(|(k, v)| format!("* {k}: {v}", k = k.bold()))
.collect::<Vec<_>>();
// Stabilize output order
plan_settings.sort();

let buf = format!(
"\
Nix uninstall plan\n\
\n\
Planner: {planner}\n\
\n\
Planner settings:\n\
\n\
{plan_settings}\n\
Nix uninstall plan (v{version})\n\
\n\
The following actions will be taken{maybe_explain}:\n\
Planner: {planner}{maybe_default_setting_note}\n\
\n\
{maybe_plan_settings}\
Planned actions:\n\
{actions}\n\
",
maybe_explain = if !explain {
" (`--explain` for more context)"
planner = planner.typetag_name(),
maybe_default_setting_note = if plan_settings.is_empty() {
String::from(" (with default settings)")
} else {
""
String::new()
},
maybe_plan_settings = if plan_settings.is_empty() {
String::new()
} else {
format!(
"\
Configured settings:\n\
{plan_settings}\n\
\n\
",
plan_settings = plan_settings.join("\n")
)
},
planner = planner.typetag_name(),
plan_settings = planner
.settings()?
.into_iter()
.map(|(k, v)| format!("* {k}: {v}", k = k.bold()))
.collect::<Vec<_>>()
.join("\n"),
actions = actions
.iter()
.rev()
Expand Down

0 comments on commit c55a59b

Please sign in to comment.