Skip to content

Commit 5ecced2

Browse files
committed
improve documentation on args and config
1 parent 754362b commit 5ecced2

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

bear/src/args.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
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
109
use 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)]
2019
pub 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)]
4645
pub 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)]
5152
pub 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)]
5761
pub 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..)

bear/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
//! This module defines the configuration of the application.
44
//!
5-
//! The configuration is either loaded from a file or used with the default
5+
//! The configuration is either loaded from a file or used with default
66
//! values, which are defined in the code. The configuration exposes the main
77
//! logical steps that the application will follow.
88
//!
99
//! The configuration file syntax is based on the YAML format.
1010
//! The default configuration file name is `bear.yml`.
1111
//!
1212
//! The configuration file location is searched in the following order:
13-
//! - The current working directory.
14-
//! - The local configuration directory of the user.
15-
//! - The configuration directory of the user.
16-
//! - The local configuration directory of the application.
17-
//! - The configuration directory of the application.
13+
//! 1. The current working directory
14+
//! 2. The local configuration directory of the user
15+
//! 3. The configuration directory of the user
16+
//! 4. The local configuration directory of the application
17+
//! 5. The configuration directory of the application
1818
//!
1919
//! ```yaml
2020
//! schema: 4.0

0 commit comments

Comments
 (0)