Groom plan synopsis (#338)

* Groom plan synopsis

* Review nits
This commit is contained in:
Ana Hobden 2023-03-16 08:56:03 -07:00 committed by GitHub
parent 89094e0d40
commit c55a59b10e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 31 deletions

View file

@ -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(),
],

View file

@ -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,

View file

@ -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,

View file

@ -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\
",
@ -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 buf = format!(
"\
Nix uninstall plan\n\
\n\
Planner: {planner}\n\
\n\
Planner settings:\n\
\n\
{plan_settings}\n\
\n\
The following actions will be taken{maybe_explain}:\n\
\n\
{actions}\n\
",
maybe_explain = if !explain {
" (`--explain` for more context)"
let plan_settings = if explain {
// List all settings when explaining
planner.settings()?
} else {
""
},
planner = planner.typetag_name(),
plan_settings = planner
.settings()?
// 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<_>>()
.join("\n"),
.collect::<Vec<_>>();
// Stabilize output order
plan_settings.sort();
let buf = format!(
"\
Nix uninstall plan (v{version})\n\
\n\
Planner: {planner}{maybe_default_setting_note}\n\
\n\
{maybe_plan_settings}\
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 {
format!(
"\
Configured settings:\n\
{plan_settings}\n\
\n\
",
plan_settings = plan_settings.join("\n")
)
},
actions = actions
.iter()
.rev()