33//! This module contains the command line interface of the application.
44//!
55//! The command line parsing is implemented using the `clap` library.
6- //! The module is defining types to represent a structured form of the
7- //! program invocation. The `Arguments` type is used to represent all
8- //! possible invocations of the program.
6+ //! The module defines types to represent a structured form of program invocation.
7+ //! The `Arguments` type is used to represent all possible invocations of the program.
98
109use clap:: { arg, command, ArgAction , ArgMatches , Command } ;
1110
@@ -18,9 +17,9 @@ const DEFAULT_EVENT_FILE: &str = "events.json";
1817/// Represents the command line arguments of the application.
1918#[ derive( Debug , PartialEq ) ]
2019pub struct Arguments {
21- // The path of the configuration file.
20+ /// The path of the configuration file.
2221 pub config : Option < String > ,
23- // The mode of the application.
22+ /// The mode of the application.
2423 pub mode : Mode ,
2524}
2625
@@ -44,17 +43,23 @@ pub enum Mode {
4443/// Represents the execution of a command.
4544#[ derive( Debug , PartialEq ) ]
4645pub struct BuildCommand {
46+ /// The command arguments to execute. (This is a non-empty vector of strings.)
4747 pub arguments : Vec < String > ,
4848}
4949
50+ /// Represents the semantic output configuration.
5051#[ derive( Debug , PartialEq ) ]
5152pub struct BuildSemantic {
53+ /// The output file path.
5254 pub path : std:: path:: PathBuf ,
55+ /// Whether to append to an existing file.
5356 pub append : bool ,
5457}
5558
59+ /// Represents the build events configuration.
5660#[ derive( Debug , PartialEq ) ]
5761pub struct BuildEvents {
62+ /// The path to the events file.
5863 pub path : std:: path:: PathBuf ,
5964}
6065
@@ -113,17 +118,13 @@ impl TryFrom<&ArgMatches> for BuildCommand {
113118
114119 fn try_from ( matches : & ArgMatches ) -> Result < Self , Self :: Error > {
115120 let arguments: Vec < _ > = matches
116- . get_many ( "COMMAND " )
121+ . get_many ( "BUILD_COMMAND " )
117122 . ok_or ( ParseError :: MissingBuildCommand ) ?
118123 . cloned ( )
119124 . collect ( ) ;
120125
121- // TODO: write test to validate we need this check.
122- if arguments. is_empty ( ) {
123- Err ( ParseError :: MissingBuildCommand )
124- } else {
125- Ok ( BuildCommand { arguments } )
126- }
126+ // The arguments must not be empty, and that is enforced by the CLI definition.
127+ Ok ( BuildCommand { arguments } )
127128 }
128129}
129130
@@ -168,7 +169,7 @@ pub fn cli() -> Command {
168169 Command :: new ( MODE_INTERCEPT_SUBCOMMAND )
169170 . about ( "intercepts command execution" )
170171 . args ( & [
171- arg ! ( <COMMAND > "Build command" )
172+ arg ! ( <BUILD_COMMAND > "Build command" )
172173 . action ( ArgAction :: Append )
173174 . value_terminator ( "--" )
174175 . num_args ( 1 ..)
@@ -196,7 +197,7 @@ pub fn cli() -> Command {
196197 . arg_required_else_help ( false ) ,
197198 )
198199 . args ( & [
199- arg ! ( <COMMAND > "Build command" )
200+ arg ! ( <BUILD_COMMAND > "Build command" )
200201 . action ( ArgAction :: Append )
201202 . value_terminator ( "--" )
202203 . num_args ( 1 ..)
0 commit comments