1
- use std:: { env, ffi:: OsString , path:: PathBuf } ;
1
+ use std:: { env, ffi:: OsString , fmt , path:: PathBuf } ;
2
2
3
3
use color_eyre:: {
4
4
Result ,
@@ -7,10 +7,17 @@ use color_eyre::{
7
7
use tracing:: { debug, info, warn} ;
8
8
9
9
use crate :: {
10
- commands,
11
- commands:: Command ,
10
+ commands:: { self , Command } ,
12
11
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 ,
14
21
update:: update,
15
22
util:: { get_hostname, print_dix_diff} ,
16
23
} ;
@@ -26,7 +33,7 @@ impl interface::HomeArgs {
26
33
match self . subcommand {
27
34
HomeSubcommand :: Switch ( args) => args. rebuild ( & Switch ) ,
28
35
HomeSubcommand :: Build ( args) => {
29
- if args. common . ask || args. common . dry {
36
+ if args. common . ask . is_some ( ) || args. common . dry {
30
37
warn ! ( "`--ask` and `--dry` have no effect for `nh home build`" ) ;
31
38
}
32
39
args. rebuild ( & Build )
@@ -42,6 +49,16 @@ enum HomeRebuildVariant {
42
49
Switch ,
43
50
}
44
51
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
+
45
62
impl HomeRebuildArgs {
46
63
fn rebuild ( self , variant : & HomeRebuildVariant ) -> Result < ( ) > {
47
64
use HomeRebuildVariant :: Build ;
@@ -150,16 +167,24 @@ impl HomeRebuildArgs {
150
167
}
151
168
152
169
if self . common . dry || matches ! ( variant, Build ) {
153
- if self . common . ask {
170
+ if self . common . ask . is_some ( ) {
154
171
warn ! ( "--ask has no effect as dry run was requested" ) ;
155
172
}
156
173
return Ok ( ( ) ) ;
157
174
}
158
175
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
+ } ;
163
188
164
189
if !confirmation {
165
190
bail ! ( "User rejected the new config" ) ;
0 commit comments