Skip to content

Commit 3564204

Browse files
committed
Order CliAction variants by category
Reorganize the enum into four groups: display/help, daemon entry (Run, Simulate, PresetCommand), daemon-affecting subcommands (RestartCommand, StopCommand, GeoCommand, TestCommand, StatusCommand), and config subcommands (SetCommand, GetCommand). main.rs and the config_dir accessor mirror this order so the match arms scan top-to-bottom in the same shape as the enum.
1 parent e928c94 commit 3564204

2 files changed

Lines changed: 77 additions & 77 deletions

File tree

src/args.rs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,41 @@ pub enum SetOperator {
3131
/// Represents the parsed command-line arguments and their intended actions.
3232
#[derive(Debug, PartialEq)]
3333
pub enum CliAction {
34+
/// Display version information and exit
35+
ShowVersion,
36+
37+
/// Display help information and exit
38+
ShowHelp,
39+
40+
/// Show help due to unknown arguments and exit
41+
ShowHelpDueToError,
42+
43+
/// Display detailed help for a specific command or general help
44+
HelpCommand { command: Option<String> },
45+
46+
/// Display usage help for a specific command (--help flag in command context)
47+
UsageHelp { command: String },
48+
49+
/// Show command-specific usage due to error
50+
ShowCommandUsageDueToError {
51+
command: String,
52+
error_message: String,
53+
},
54+
3455
/// Run the normal application with these settings
3556
Run {
3657
debug_enabled: bool,
3758
config_dir: Option<String>,
3859
background: bool,
3960
},
4061

41-
/// Test using subcommand syntax
42-
TestCommand {
43-
debug_enabled: bool,
44-
temperature: u32,
45-
gamma: f64,
46-
config_dir: Option<String>,
47-
},
48-
49-
/// Geo using subcommand syntax
50-
GeoCommand {
62+
/// Simulate time passing for testing
63+
Simulate {
5164
debug_enabled: bool,
65+
start_time: String,
66+
end_time: String,
67+
multiplier: f64,
68+
log_to_file: bool,
5269
config_dir: Option<String>,
5370
},
5471

@@ -59,35 +76,32 @@ pub enum CliAction {
5976
config_dir: Option<String>,
6077
},
6178

62-
/// Set configuration field subcommand
63-
SetCommand {
79+
/// Restart using subcommand syntax
80+
RestartCommand {
6481
debug_enabled: bool,
65-
fields: Vec<(String, SetOperator, String)>,
82+
instant: bool,
6683
config_dir: Option<String>,
67-
target: Option<String>,
84+
background: bool,
6885
},
6986

70-
/// Get configuration field subcommand
71-
GetCommand {
87+
/// Stop using subcommand syntax
88+
StopCommand {
7289
debug_enabled: bool,
73-
fields: Vec<String>,
7490
config_dir: Option<String>,
75-
target: Option<String>,
76-
json: bool,
7791
},
7892

79-
/// Stop using subcommand syntax
80-
StopCommand {
93+
/// Geo using subcommand syntax
94+
GeoCommand {
8195
debug_enabled: bool,
8296
config_dir: Option<String>,
8397
},
8498

85-
/// Restart using subcommand syntax
86-
RestartCommand {
99+
/// Test using subcommand syntax
100+
TestCommand {
87101
debug_enabled: bool,
88-
instant: bool,
102+
temperature: u32,
103+
gamma: f64,
89104
config_dir: Option<String>,
90-
background: bool,
91105
},
92106

93107
/// Status command - display current runtime state
@@ -97,35 +111,21 @@ pub enum CliAction {
97111
follow: bool,
98112
},
99113

100-
/// Display detailed help for a specific command or general help
101-
HelpCommand { command: Option<String> },
102-
103-
/// Display usage help for a specific command (--help flag in command context)
104-
UsageHelp { command: String },
105-
106-
/// Simulate time passing for testing
107-
Simulate {
114+
/// Set configuration field subcommand
115+
SetCommand {
108116
debug_enabled: bool,
109-
start_time: String,
110-
end_time: String,
111-
multiplier: f64,
112-
log_to_file: bool,
117+
fields: Vec<(String, SetOperator, String)>,
113118
config_dir: Option<String>,
119+
target: Option<String>,
114120
},
115121

116-
/// Display help information and exit
117-
ShowHelp,
118-
119-
/// Display version information and exit
120-
ShowVersion,
121-
122-
/// Show help due to unknown arguments and exit
123-
ShowHelpDueToError,
124-
125-
/// Show command-specific usage due to error
126-
ShowCommandUsageDueToError {
127-
command: String,
128-
error_message: String,
122+
/// Get configuration field subcommand
123+
GetCommand {
124+
debug_enabled: bool,
125+
fields: Vec<String>,
126+
config_dir: Option<String>,
127+
target: Option<String>,
128+
json: bool,
129129
},
130130
}
131131

@@ -134,14 +134,14 @@ impl CliAction {
134134
pub fn config_dir(&self) -> Option<&str> {
135135
match self {
136136
Self::Run { config_dir, .. }
137-
| Self::TestCommand { config_dir, .. }
138-
| Self::GeoCommand { config_dir, .. }
137+
| Self::Simulate { config_dir, .. }
139138
| Self::PresetCommand { config_dir, .. }
140-
| Self::SetCommand { config_dir, .. }
141-
| Self::GetCommand { config_dir, .. }
142-
| Self::StopCommand { config_dir, .. }
143139
| Self::RestartCommand { config_dir, .. }
144-
| Self::Simulate { config_dir, .. } => config_dir.as_deref(),
140+
| Self::StopCommand { config_dir, .. }
141+
| Self::GeoCommand { config_dir, .. }
142+
| Self::TestCommand { config_dir, .. }
143+
| Self::SetCommand { config_dir, .. }
144+
| Self::GetCommand { config_dir, .. } => config_dir.as_deref(),
145145
_ => None,
146146
}
147147
}

src/main.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,11 @@ fn main() -> Result<()> {
7070
}
7171
Ok(())
7272
}
73-
CliAction::GeoCommand { debug_enabled, .. } => {
74-
commands::geo::handle_geo_command(debug_enabled)
75-
}
76-
CliAction::RestartCommand {
77-
debug_enabled,
78-
instant,
79-
background,
80-
..
81-
} => commands::restart::handle_restart_command(instant, debug_enabled, background),
82-
CliAction::StopCommand { debug_enabled, .. } => {
83-
commands::stop::handle_stop_command(debug_enabled)
84-
}
8573
CliAction::Run {
8674
debug_enabled,
8775
background,
8876
..
8977
} => Sunsetr::new(debug_enabled).background(background).run(),
90-
CliAction::TestCommand {
91-
debug_enabled,
92-
temperature,
93-
gamma,
94-
..
95-
} => commands::test::handle_test_command(temperature, gamma, debug_enabled),
9678
CliAction::Simulate {
9779
debug_enabled,
9880
start_time,
@@ -131,6 +113,27 @@ fn main() -> Result<()> {
131113
Sunsetr::new(debug_enabled).without_headers().run()
132114
}
133115
},
116+
CliAction::RestartCommand {
117+
debug_enabled,
118+
instant,
119+
background,
120+
..
121+
} => commands::restart::handle_restart_command(instant, debug_enabled, background),
122+
CliAction::StopCommand { debug_enabled, .. } => {
123+
commands::stop::handle_stop_command(debug_enabled)
124+
}
125+
CliAction::GeoCommand { debug_enabled, .. } => {
126+
commands::geo::handle_geo_command(debug_enabled)
127+
}
128+
CliAction::TestCommand {
129+
debug_enabled,
130+
temperature,
131+
gamma,
132+
..
133+
} => commands::test::handle_test_command(temperature, gamma, debug_enabled),
134+
CliAction::StatusCommand { json, follow, .. } => {
135+
commands::status::handle_status_command(json, follow)
136+
}
134137
CliAction::SetCommand { fields, target, .. } => {
135138
commands::set::handle_set_command(fields, target.as_deref())
136139
}
@@ -140,8 +143,5 @@ fn main() -> Result<()> {
140143
json,
141144
..
142145
} => commands::get::handle_get_command(&fields, target.as_deref(), json),
143-
CliAction::StatusCommand { json, follow, .. } => {
144-
commands::status::handle_status_command(json, follow)
145-
}
146146
}
147147
}

0 commit comments

Comments
 (0)