-
-
Notifications
You must be signed in to change notification settings - Fork 101
various: system notifications #387
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use std::{env, path::PathBuf}; | ||
| use std::{env, fmt, path::PathBuf}; | ||
|
|
||
| use color_eyre::eyre::{Context, bail, eyre}; | ||
| use tracing::{debug, warn}; | ||
|
|
@@ -14,8 +14,10 @@ use crate::{ | |
| DarwinReplArgs, | ||
| DarwinSubcommand, | ||
| DiffType, | ||
| NotifyAskMode, | ||
| }, | ||
| nixos::toplevel_for, | ||
| notify::NotificationSender, | ||
| update::update, | ||
| util::{get_hostname, print_dix_diff}, | ||
| }; | ||
|
|
@@ -34,7 +36,7 @@ impl DarwinArgs { | |
| match self.subcommand { | ||
| DarwinSubcommand::Switch(args) => args.rebuild(&Switch, elevation), | ||
| DarwinSubcommand::Build(args) => { | ||
| if args.common.ask || args.common.dry { | ||
| if args.common.ask.is_some() || args.common.dry { | ||
| warn!("`--ask` and `--dry` have no effect for `nh darwin build`"); | ||
| } | ||
| args.rebuild(&Build, elevation) | ||
|
|
@@ -49,6 +51,16 @@ enum DarwinRebuildVariant { | |
| Build, | ||
| } | ||
|
|
||
| impl fmt::Display for DarwinRebuildVariant { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| let s = match self { | ||
| DarwinRebuildVariant::Build => "build", | ||
| DarwinRebuildVariant::Switch => "switch", | ||
| }; | ||
| write!(f, "{s}") | ||
| } | ||
| } | ||
|
|
||
| impl DarwinRebuildArgs { | ||
| fn rebuild( | ||
| self, | ||
|
|
@@ -144,13 +156,27 @@ impl DarwinRebuildArgs { | |
| let _ = print_dix_diff(&PathBuf::from(CURRENT_PROFILE), &target_profile); | ||
| } | ||
|
|
||
| if self.common.ask && !self.common.dry && !matches!(variant, Build) { | ||
| let confirmation = inquire::Confirm::new("Apply the config?") | ||
| .with_default(false) | ||
| .prompt()?; | ||
| if !self.common.dry && !matches!(variant, Build) { | ||
| if let Some(ask) = self.common.ask { | ||
| let confirmation = match ask { | ||
| NotifyAskMode::Prompt => { | ||
| inquire::Confirm::new("Apply the config?") | ||
| .with_default(false) | ||
| .prompt()? | ||
| }, | ||
| #[cfg(all(unix, not(target_os = "macos")))] | ||
| NotifyAskMode::Notify => { | ||
| NotificationSender::new( | ||
| &format!("nh darwin {variant}"), | ||
| "Do you want to apply the Darwin configuration?", | ||
| ) | ||
| .ask() | ||
| }, | ||
| }; | ||
|
Comment on lines
+168
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle notification backend failures gracefully.
#[cfg(all(unix, not(target_os = "macos")))]
NotifyAskMode::Notify => {
- NotificationSender::new(
- &format!("nh darwin {variant}"),
- "Do you want to apply the Darwin configuration?",
- )
- .ask()
+ match NotificationSender::new(
+ &format!("nh darwin {variant}"),
+ "Do you want to apply the Darwin configuration?",
+ )
+ .ask()
+ {
+ Ok(confirmed) => confirmed,
+ Err(e) => {
+ debug!(?e, "Notification prompt failed; falling back to terminal prompt");
+ inquire::Confirm::new("Apply the config?")
+ .with_default(false)
+ .prompt()?
+ }
+ }
},Do the corresponding
🤖 Prompt for AI Agents |
||
|
|
||
| if !confirmation { | ||
| bail!("User rejected the new config"); | ||
| if !confirmation { | ||
| bail!("User rejected the new config"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,15 +264,24 @@ pub enum DiffType { | |
| Never, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, ValueEnum, PartialEq)] | ||
| pub enum NotifyAskMode { | ||
| /// Ask in the terminal (stdin prompt) | ||
| Prompt, | ||
| /// Ask via a desktop notification action | ||
| #[cfg(all(unix, not(target_os = "macos")))] | ||
| Notify, | ||
| } | ||
|
|
||
| #[derive(Debug, Args)] | ||
| pub struct OsRollbackArgs { | ||
| /// Only print actions, without performing them | ||
| #[arg(long, short = 'n')] | ||
| pub dry: bool, | ||
|
|
||
| /// Ask for confirmation | ||
| #[arg(long, short)] | ||
| pub ask: bool, | ||
| #[arg(long, short, value_enum, default_missing_value = "prompt", num_args = 0..=1)] | ||
| pub ask: Option<NotifyAskMode>, | ||
|
Comment on lines
+283
to
+284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainCritical: Missing
Apply this fix: /// Ask for confirmation
- #[arg(long, short, default_missing_value = "prompt", num_args = 0..=1)]
+ #[arg(long, short, value_enum, default_missing_value = "prompt", num_args = 0..=1)]
pub ask: Option<NotifyAskMode>,for both Run this script to verify all Also applies to: 316-317, 448-449 🏁 Script executed: #!/bin/bash
# Find all ask field declarations and their attributes
rg -n -A1 -B1 'pub ask: Option<NotifyAskMode>' src/interface.rs
# Check which ones have value_enum in their clap attribute
rg -n -B2 'pub ask: Option<NotifyAskMode>' src/interface.rs | grep -E '(#\[arg|pub ask)'Length of output: 740 🏁 Script executed: #!/bin/bash
# Find NotifyAskMode definition and its traits/derives
rg -n -A10 'enum NotifyAskMode' src/interface.rs
# Check if NotifyAskMode is derived with any trait that enables FromStr
rg -n -B5 'enum NotifyAskMode' src/interface.rs | head -20Length of output: 440 🏁 Script executed: #!/bin/bash
# Search for any FromStr implementation for NotifyAskMode
rg -n 'impl.*FromStr.*NotifyAskMode|NotifyAskMode.*FromStr' src/
# Also search for clap derive or value_enum usage patterns
rg -n '#\[derive.*Clap|#\[derive.*ValueEnum' src/interface.rs | head -10Length of output: 136 🏁 Script executed: #!/bin/bash
# Search for tests exercising the --ask flag
rg -n '\-\-ask|ask.*Option.*NotifyAskMode' tests/ --type rust 2>/dev/null | head -20
# Also check if there's any test or integration test
fd -e rs tests/ 2>/dev/null | head -10Length of output: 0 🏁 Script executed: #!/bin/bash
# Check clap's ValueEnum behavior - verify that derived ValueEnum works without explicit value_enum attribute
# Search for any documentation or comments about this pattern
rg -n 'ValueEnum|value_enum' src/interface.rs | head -20Length of output: 438 Add missing The verification confirms the issue:
Apply this fix to lines 316 and 448: - #[arg(long, short, default_missing_value = "prompt", num_args = 0..=1)]
+ #[arg(long, short, value_enum, default_missing_value = "prompt", num_args = 0..=1)]
pub ask: Option<NotifyAskMode>,
🤖 Prompt for AI Agents |
||
|
|
||
| /// Explicitly select some specialisation | ||
| #[arg(long, short)] | ||
|
|
@@ -303,8 +312,8 @@ pub struct CommonRebuildArgs { | |
| pub dry: bool, | ||
|
|
||
| /// Ask for confirmation | ||
| #[arg(long, short)] | ||
| pub ask: bool, | ||
| #[arg(long, short, default_missing_value = "prompt", num_args = 0..=1)] | ||
| pub ask: Option<NotifyAskMode>, | ||
|
|
||
| #[command(flatten)] | ||
| pub installable: Installable, | ||
|
|
@@ -435,8 +444,8 @@ pub struct CleanArgs { | |
| pub dry: bool, | ||
|
|
||
| /// Ask for confirmation | ||
| #[arg(long, short)] | ||
| pub ask: bool, | ||
| #[arg(long, short, default_missing_value = "prompt", num_args = 0..=1)] | ||
| pub ask: Option<NotifyAskMode>, | ||
|
|
||
| /// Don't run nix store --gc | ||
| #[arg(long = "no-gc", alias = "nogc")] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ mod interface; | |
| mod json; | ||
| mod logging; | ||
| mod nixos; | ||
| mod notify; | ||
| mod search; | ||
| mod update; | ||
| mod util; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.