@@ -27,7 +27,7 @@ struct Cli {
2727 markdown_help : bool ,
2828}
2929
30- /// Options for the run command
30+ /// Options for the ` run` command
3131#[ derive( Args ) ]
3232pub struct RunOpts {
3333 /// Directory for output files
@@ -41,6 +41,17 @@ pub struct RunOpts {
4141 pub debug_model : bool ,
4242}
4343
44+ /// Options for the `graph` command
45+ #[ derive( Args ) ]
46+ pub struct GraphOpts {
47+ /// Directory for graph files
48+ #[ arg( short, long) ]
49+ pub output_dir : Option < PathBuf > ,
50+ /// Whether to overwrite the output directory if it already exists
51+ #[ arg( long) ]
52+ pub overwrite : bool ,
53+ }
54+
4455/// The available commands.
4556#[ derive( Subcommand ) ]
4657enum Commands {
@@ -64,12 +75,12 @@ enum Commands {
6475 model_dir : PathBuf ,
6576 } ,
6677 /// Build and output commodity flow graphs for a model.
67- BuildCommodityGraphs {
78+ Graph {
6879 /// The path to the model directory.
6980 model_dir : PathBuf ,
70- /// Other options (uses the same settings as the `run` command)
81+ /// Other options
7182 #[ command( flatten) ]
72- opts : RunOpts ,
83+ opts : GraphOpts ,
7384 } ,
7485 /// Manage settings file.
7586 Settings {
@@ -86,9 +97,7 @@ impl Commands {
8697 Self :: Run { model_dir, opts } => handle_run_command ( & model_dir, & opts, None ) ,
8798 Self :: Example { subcommand } => subcommand. execute ( ) ,
8899 Self :: Validate { model_dir } => handle_validate_command ( & model_dir, None ) ,
89- Self :: BuildCommodityGraphs { model_dir, opts } => {
90- handle_build_commodity_graphs_command ( & model_dir, & opts, None )
91- }
100+ Self :: Graph { model_dir, opts } => handle_graph_command ( & model_dir, & opts, None ) ,
92101 Self :: Settings { subcommand } => subcommand. execute ( ) ,
93102 }
94103 }
@@ -191,10 +200,10 @@ pub fn handle_validate_command(model_path: &Path, settings: Option<Settings>) ->
191200 Ok ( ( ) )
192201}
193202
194- /// Handle the `build-commodity-graphs ` command.
195- pub fn handle_build_commodity_graphs_command (
203+ /// Handle the `graph ` command.
204+ pub fn handle_graph_command (
196205 model_path : & Path ,
197- opts : & RunOpts ,
206+ opts : & GraphOpts ,
198207 settings : Option < Settings > ,
199208) -> Result < ( ) > {
200209 // Load program settings, if not provided
@@ -205,9 +214,6 @@ pub fn handle_build_commodity_graphs_command(
205214 } ;
206215
207216 // These settings can be overridden by command-line arguments
208- if opts. debug_model {
209- settings. debug_model = true ;
210- }
211217 if opts. overwrite {
212218 settings. overwrite = true ;
213219 }
@@ -224,24 +230,23 @@ pub fn handle_build_commodity_graphs_command(
224230 let overwrite =
225231 create_output_directory ( output_path, settings. overwrite ) . with_context ( || {
226232 format ! (
227- "Failed to create commodity flow graphs directory: {}" ,
233+ "Failed to create graphs directory: {}" ,
228234 output_path. display( )
229235 )
230236 } ) ?;
231237
232- // Initialise program logger (we won't save log files when running this command
238+ // Initialise program logger (we won't save log files when running this command)
233239 log:: init ( & settings. log_level , None ) . context ( "Failed to initialise logging." ) ?;
234240
235241 // NB: We have to wait until the logger is initialised to display this warning
236242 if overwrite {
237- warn ! ( "Commodity flow graphs directory will be overwritten" ) ;
243+ warn ! ( "Graphs directory will be overwritten" ) ;
238244 }
239245
240246 // Load commodity flow graphs and save to file
241- let commodity_graphs =
242- load_commodity_graphs ( model_path) . context ( "Failed to build commodity flow graphs." ) ?;
247+ let commodity_graphs = load_commodity_graphs ( model_path) . context ( "Failed to build graphs." ) ?;
243248 save_commodity_graphs_for_model ( & commodity_graphs, output_path) ?;
244- info ! ( "Commodity flow graphs saved to file" ) ;
249+ info ! ( "Graphs saved to file" ) ;
245250
246251 Ok ( ( ) )
247252}
0 commit comments