1- use std:: { env, ffi:: OsString , path:: PathBuf } ;
1+ use std:: { env, ffi:: OsString , fmt , path:: PathBuf } ;
22
33use color_eyre:: {
44 Result ,
@@ -7,10 +7,17 @@ use color_eyre::{
77use tracing:: { debug, info, warn} ;
88
99use crate :: {
10- commands,
11- commands:: Command ,
10+ commands:: { self , Command } ,
1211 installable:: Installable ,
13- interface:: { self , DiffType , HomeRebuildArgs , HomeReplArgs , HomeSubcommand } ,
12+ interface:: {
13+ self ,
14+ DiffType ,
15+ HomeRebuildArgs ,
16+ HomeReplArgs ,
17+ HomeSubcommand ,
18+ NotifyAskMode ,
19+ } ,
20+ notify:: NotificationSender ,
1421 update:: update,
1522 util:: { get_hostname, print_dix_diff} ,
1623} ;
@@ -26,7 +33,7 @@ impl interface::HomeArgs {
2633 match self . subcommand {
2734 HomeSubcommand :: Switch ( args) => args. rebuild ( & Switch ) ,
2835 HomeSubcommand :: Build ( args) => {
29- if args. common . ask || args. common . dry {
36+ if args. common . ask . is_some ( ) || args. common . dry {
3037 warn ! ( "`--ask` and `--dry` have no effect for `nh home build`" ) ;
3138 }
3239 args. rebuild ( & Build )
@@ -42,6 +49,16 @@ enum HomeRebuildVariant {
4249 Switch ,
4350}
4451
52+ impl fmt:: Display for HomeRebuildVariant {
53+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
54+ let s = match self {
55+ HomeRebuildVariant :: Build => "build" ,
56+ HomeRebuildVariant :: Switch => "switch" ,
57+ } ;
58+ write ! ( f, "{s}" )
59+ }
60+ }
61+
4562impl HomeRebuildArgs {
4663 fn rebuild ( self , variant : & HomeRebuildVariant ) -> Result < ( ) > {
4764 use HomeRebuildVariant :: Build ;
@@ -150,16 +167,24 @@ impl HomeRebuildArgs {
150167 }
151168
152169 if self . common . dry || matches ! ( variant, Build ) {
153- if self . common . ask {
170+ if self . common . ask . is_some ( ) {
154171 warn ! ( "--ask has no effect as dry run was requested" ) ;
155172 }
156173 return Ok ( ( ) ) ;
157174 }
158175
159- if self . common . ask {
160- let confirmation = inquire:: Confirm :: new ( "Apply the config?" )
161- . with_default ( false )
162- . prompt ( ) ?;
176+ if let Some ( ask) = self . common . ask {
177+ let confirmation = match ask {
178+ NotifyAskMode :: Prompt => {
179+ inquire:: Confirm :: new ( "Apply the config?" )
180+ . with_default ( false )
181+ . prompt ( ) ?
182+ } ,
183+ NotifyAskMode :: Notify => {
184+ NotificationSender :: new ( "nh os rollback" , "testing" ) . ask ( )
185+ } ,
186+ NotifyAskMode :: Both => unimplemented ! ( ) ,
187+ } ;
163188
164189 if !confirmation {
165190 bail ! ( "User rejected the new config" ) ;
0 commit comments