Reform positional argument parsing (#523)

This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.

User-visible changes:

- `just ..` is now accepted, with the same effect as `just ../`

- `just .` is also accepted, with the same effect as `just`

- It is now an error to pass arguments or overrides to subcommands
  that do not accept them, namely `--dump`, `--edit`, `--list`,
  `--show`, and `--summary`. It is also an error to pass arguments to
  `--evaluate`, although `--evaluate` does of course still accept
  overrides.

  (This is a breaking change, but hopefully worth it, as it will allow us
  to add arguments to subcommands which did not previously take
  them, if we so desire.)

- Subcommands which do not accept arguments may now accept a
  single search-directory argument, so `just --list ../` and
  `just --dump foo/` are now accepted, with the former starting the
  search for the justfile to list in the parent directory, and the latter
  starting the search for the justfile to dump in `foo`.
This commit is contained in:
Casey Rodarmor
2019-11-10 18:02:36 -08:00
committed by GitHub
parent aefdcea7d0
commit 177516bcbe
15 changed files with 953 additions and 448 deletions

41
tests/readme.rs Normal file
View File

@@ -0,0 +1,41 @@
use std::{fs, process::Command};
use executable_path::executable_path;
use test_utilities::{assert_success, tempdir};
#[test]
fn readme() {
let mut justfiles = vec![];
let mut current = None;
for line in fs::read_to_string("README.adoc").unwrap().lines() {
if let Some(mut justfile) = current {
if line == "```" {
justfiles.push(justfile);
current = None;
} else {
justfile += line;
justfile += "\n";
current = Some(justfile);
}
} else if line == "```make" {
current = Some(String::new());
}
}
for justfile in justfiles {
let tmp = tempdir();
let path = tmp.path().join("justfile");
fs::write(&path, &justfile).unwrap();
let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.arg("--dump")
.output()
.unwrap();
assert_success(&output);
}
}

View File

@@ -121,3 +121,27 @@ fn test_downwards_multiple_path_argument() {
search_test(&path, &["./a/b/"]);
search_test(&path, &["./a/b/default"]);
}
#[test]
fn single_downards() {
let tmp = tmptree! {
justfile: "default:\n\techo ok",
child: {},
};
let path = tmp.path();
search_test(&path, &["child/"]);
}
#[test]
fn single_upwards() {
let tmp = tmptree! {
justfile: "default:\n\techo ok",
child: {},
};
let path = tmp.path().join("child");
search_test(&path, &["../"]);
}