Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groom plan synopsis #338

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, I totally forgot to do this here as well 😅

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