File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,6 +129,24 @@ pub enum CliAction {
129129 } ,
130130}
131131
132+ impl CliAction {
133+ /// Returns the custom config directory carried by this action, if any.
134+ pub fn config_dir ( & self ) -> Option < & str > {
135+ match self {
136+ Self :: Run { config_dir, .. }
137+ | Self :: TestCommand { config_dir, .. }
138+ | Self :: GeoCommand { config_dir, .. }
139+ | Self :: PresetCommand { config_dir, .. }
140+ | Self :: SetCommand { config_dir, .. }
141+ | Self :: GetCommand { config_dir, .. }
142+ | Self :: StopCommand { config_dir, .. }
143+ | Self :: RestartCommand { config_dir, .. }
144+ | Self :: Simulate { config_dir, .. } => config_dir. as_deref ( ) ,
145+ _ => None ,
146+ }
147+ }
148+ }
149+
132150/// Result of parsing command-line arguments.
133151pub struct ParsedArgs {
134152 pub action : CliAction ,
Original file line number Diff line number Diff line change @@ -17,21 +17,8 @@ use sunsetr::{
1717fn main ( ) -> Result < ( ) > {
1818 let parsed_args = ParsedArgs :: from_env ( ) ;
1919
20- let config_dir = match & parsed_args. action {
21- CliAction :: Run { config_dir, .. }
22- | CliAction :: TestCommand { config_dir, .. }
23- | CliAction :: GeoCommand { config_dir, .. }
24- | CliAction :: PresetCommand { config_dir, .. }
25- | CliAction :: SetCommand { config_dir, .. }
26- | CliAction :: GetCommand { config_dir, .. }
27- | CliAction :: StopCommand { config_dir, .. }
28- | CliAction :: RestartCommand { config_dir, .. }
29- | CliAction :: Simulate { config_dir, .. } => config_dir. clone ( ) ,
30- _ => None ,
31- } ;
32-
33- if let Some ( dir) = config_dir
34- && let Err ( e) = config:: set_config_dir ( Some ( dir) )
20+ if let Some ( dir) = parsed_args. action . config_dir ( )
21+ && let Err ( e) = config:: set_config_dir ( Some ( dir. to_string ( ) ) )
3522 {
3623 log_error_exit ! ( "{}" , e) ;
3724 }
You can’t perform that action at this time.
0 commit comments