Skip to content

Commit 94ecd0f

Browse files
pacakfacebook-github-bot
authored andcommitted
Fix command line option parsing (#86)
Summary: Positional arguments in 0.9 version of bpaf must go to the right most position. Fixes #85 Pull Request resolved: #86 Test Plan: - CI, it includes new tests Reviewed By: jcpetruzza Differential Revision: D70096890 Pulled By: alanz fbshipit-source-id: 87518036f3ed61e899b995e7009784c49e67c918
1 parent 893c2ea commit 94ecd0f

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

crates/elp/src/bin/args.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ pub struct EqwalizeTarget {
151151
pub project: PathBuf,
152152
/// Also eqwalize opted-in generated modules from application
153153
pub include_generated: bool,
154-
/// target, like //erl/chatd/...
155-
#[bpaf(positional::< String > ("TARGET"))]
156-
pub target: String,
157154
/// Use experimental clause coverage checker
158155
pub clause_coverage: bool,
159156
/// Exit with a non-zero status code if any errors are found
160157
pub bail_on_error: bool,
158+
/// target, like //erl/chatd/...
159+
#[bpaf(positional("TARGET"))]
160+
pub target: String,
161161
}
162162

163163
#[derive(Clone, Debug, Bpaf)]
@@ -172,13 +172,13 @@ pub struct EqwalizeApp {
172172
pub include_generated: bool,
173173
/// Run with rebar
174174
pub rebar: bool,
175-
/// app name
176-
#[bpaf(positional::< String > ("APP"))]
177-
pub app: String,
178175
/// Use experimental clause coverage checker
179176
pub clause_coverage: bool,
180177
/// Exit with a non-zero status code if any errors are found
181178
pub bail_on_error: bool,
179+
/// app name
180+
#[bpaf(positional::< String > ("APP"))]
181+
pub app: String,
182182
}
183183

184184
#[derive(Clone, Debug, Bpaf)]
@@ -684,3 +684,16 @@ impl ParseAllElp {
684684
self.format == Some("json".to_string())
685685
}
686686
}
687+
688+
#[cfg(test)]
689+
mod tests {
690+
691+
use bpaf::Parser;
692+
693+
use super::command;
694+
695+
#[test]
696+
fn check_options() {
697+
command().to_options().check_invariants(false)
698+
}
699+
}

crates/elp/src/bin/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,8 @@ mod tests {
17571757
}
17581758
}
17591759

1760+
// -----------------------------------------------------------------
1761+
17601762
#[test]
17611763
fn help() {
17621764
let args = args::args().run_inner(Args::from(&["--help"])).unwrap_err();
@@ -1785,6 +1787,26 @@ mod tests {
17851787
expected.assert_eq(&stdout);
17861788
}
17871789

1790+
#[test]
1791+
fn eqwalize_target_help() {
1792+
let args = args::args()
1793+
.run_inner(Args::from(&["eqwalize-target", "--help"]))
1794+
.unwrap_err();
1795+
let expected = expect_file!["../resources/test/eqwalize_target_help.stdout"];
1796+
let stdout = args.unwrap_stdout();
1797+
expected.assert_eq(&stdout);
1798+
}
1799+
1800+
#[test]
1801+
fn eqwalize_app_help() {
1802+
let args = args::args()
1803+
.run_inner(Args::from(&["eqwalize-app", "--help"]))
1804+
.unwrap_err();
1805+
let expected = expect_file!["../resources/test/eqwalize_app.stdout"];
1806+
let stdout = args.unwrap_stdout();
1807+
expected.assert_eq(&stdout);
1808+
}
1809+
17881810
#[test]
17891811
fn dialyze_all_help() {
17901812
let args = args::args()
@@ -1875,6 +1897,8 @@ mod tests {
18751897
expected.assert_eq(&stdout);
18761898
}
18771899

1900+
// -----------------------------------------------------------------
1901+
18781902
#[test]
18791903
fn explain_code() {
18801904
let args = args_vec!["explain", "--code", "W0005"];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Usage: [--project PROJECT] [--as PROFILE] [--include-generated] [--rebar] [--clause-coverage] [--bail-on-error] <APP>
2+
3+
Available positional items:
4+
<APP> app name
5+
6+
Available options:
7+
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
8+
--as <PROFILE> Rebar3 profile to pickup (default is test)
9+
--include-generated Also eqwalize opted-in generated modules from project
10+
--rebar Run with rebar
11+
--clause-coverage Use experimental clause coverage checker
12+
--bail-on-error Exit with a non-zero status code if any errors are found
13+
-h, --help Prints help information
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Usage: [--project PROJECT] [--include-generated] [--clause-coverage] [--bail-on-error] <TARGET>
2+
3+
Available positional items:
4+
<TARGET> target, like //erl/chatd/...
5+
6+
Available options:
7+
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
8+
--include-generated Also eqwalize opted-in generated modules from application
9+
--clause-coverage Use experimental clause coverage checker
10+
--bail-on-error Exit with a non-zero status code if any errors are found
11+
-h, --help Prints help information

0 commit comments

Comments
 (0)