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`.
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
Moves the code which executes subcommands into Subcommand:run,
delegating to separate functions for each subcommand. This reduces the
disgustingness of `run::run` a bit, and paves the way for future
refactoring and cleanup.
Move `env::set_current_dir` outside of `Config::from_matches()` and into
`run()`. It's a bit cleaner this way, and sets us up to make the just
process not change its own directory at all, instead explicitly changing
the working directory of its child processes.
Borrow errors produced by an older version of rust forced us to create
copies of errors in the recipe resolver. The borrow checker appears to
have evolved to the point where these copies are unnecessary, so this
diff removes them.
Just's first parser performed both parsing, i.e the transformation of a
token stream according to the language grammar, and a number of consistency
checks and analysis passes.
This made parsing and analysis quite complex, so this diff introduces a
new, much cleaner `Parser`, and moves existing analysis into a dedicated
`Analyzer`.
Until github.com/rust-lang/cargo/pull/7333 makes it into stable rust,
we'll be forced to publish using nightly, due to our unpublished dev
dependency on `test-utilities`.
- Differentiate between `arg`s, which are flags and options, and `cmd`s,
which are mutually exclusive subcommands
- Replace string literals, like "EVALUATE", with constants, like
`cmd::EVALUATE`, since they're slightly less error prone.
- Remove `Config::evaluate`, and handle it like other subcommands
- Refactor the lexer tests to be more readable, abandoning the
previous string-based summary DSL in favor of a more obvious
sequence of `TokenKinds` with optional lexemes. The new tests
also test that token lexemes are correct.
- Move duplicated `unindent` function into a shared crate,
`test-utilities`. This new versionless dev-dependency will
prevent publishing to crates.io, at least until rust-lang/cargo/pull/7333
makes it into stable. If we publish a new version before then,
test-utilities will need to be published to crates.io, so we can depend
on it by version.
Checks that we build and pass tests with the minimal dependency versions
declared declared in Cargo.toml, as part of the `publish-check` recipe
run before publishing a new version of Just.
Since error code 1 is commonly used to indicate failure, change those
integration tests which test that a specific error code is returned to
use something other than 1.
run::run() is pretty unwieldy. As a first step in improving it, this
commit pulls most of the argument parsing into the `config` module.
It also renames `Configuration` to `Config`, just to be easier to type.
Adds an `unindent()` function that strips common leading indentation
from strings, and apply it to integration test case strings, so that they
can be written in a more readable style.
This commit changes the integration tests to run with bash
as the shell, instead of bash, dash, and the system's sh.
Running the integration tests with multiple shells has never
revealed a bug in Just, and they make the tests take longer,
so let's get rid of them.
Previously, warnings upon encountering a deprecated use `=` in
assignments, exports, and aliases would print a message without any
indication of where the offending `=` was. This diff adds a proper
`Warning` enum, and uses it to report context, as is done with
compilation and runtime errors.
Eventually, there will probably be a `crate` visibility specifier that
does the same thing as `pub(crate)`. This commit replaces `pub` with
`pub(crate)`, so when `crate` is available we can easily switch to it.
Just uses github.com/japaric/trust to for continuous integration and
release building. trust uses github.com/rust-embedded/cross, which no
longer supports FreeBSD. (See github.com/rust-embedded/cross/issues/274
for details.)
Sadly, it's probably too much work to dive in and fix the FreeBSD image
for cross, so this commit disables the FreeBSD builds and releases on
Travis. I don't think we've ever seen a build failure on BSD only, so
losing the test coverage isn't a big deal.
It is unfortunate that we'll lose FreeBSD release builds though. I don't
think Just is in the FreeBSd ports tree, so it would be nice if someone
wanted to package it and get it in there.
Given the following justfile:
alias b := build
build:
echo 'Building!'
Just will show the alias along with the recipe:
$ just --show b
alias b := build
build:
echo 'Building!'
The generated man page doesn't look great by default, so this also adds the
help4help2man feature, which makes Just print a help message that produces
a better man page.
Just's dependency on brev was the cause of a
fairly deep branch of the transitive dependency
tree. To decrease build time and make the life of
packagers easier, this diff moves the functionality
that Just was using in Brev into Just itself, and
removes the dependency on Brev.
Fortunately, the only functionality that Just was
using was the output function and OutputError
enum, so this was easily done.
In order to make the life of downstream packagers easier, we should take care that dependency version requirements in Cargo.toml are as minimal as possible, so that packagers have as much flexibility as possible in packaging Just and its dependencies.
This diff reduces dependency version requirements in Cargo.toml to the minimum possible, i.e. the minimum possible semver compatible version that builds and passes tests.
We continue to require patch versions of ctrlc and log, because I couldn't get just to build with minimal versions after removing their patch requirements.
The old version often failed due to rebase conflicts if the feature branch to delete had multiple commits and was squash-merged into master.
This version just checks that the up-to-date master branch matches the feature branch and uses -D to delete the feature branch. This guarantees that we don't lose any work, and avoids bad rebases from squash merges to master.