Commit Graph

134 Commits

Author SHA1 Message Date
Casey Rodarmor
598f1c3200
Refactor Compilation error to contain a Token (#535)
Use a `Token` to represent the error context, instead of a mess of
fields. Remove write_message_context in favor of `Token::write_context`.
2019-11-13 19:32:50 -08:00
Casey Rodarmor
e80bf34d9a
Add shell setting (#525)
Add a `set SETTING := VALUE` construct.

This construct is intended to be extended as needed with new settings,
but for now we're starting with `set shell := [COMMAND, ARG1, ...]`,
which allows setting the shell to use for recipe and backtick execution
in a justfile.

One of the primary reasons for adding this feature is to have a better
story on windows, where users are forced to scrounge up an `sh` binary
if they want to use `just`. This should allow them to use cmd.exe or
powershell in their justfiles, making just optionally dependency-free.
2019-11-10 23:17:47 -08:00
Casey Rodarmor
177516bcbe
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`.
2019-11-10 18:02:36 -08:00
Casey Rodarmor
aefdcea7d0
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
Casey Rodarmor
b2285ce0e0
Reform Parser (#509)
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`.
2019-11-07 10:55:15 -08:00
Casey Rodarmor
3de31b3c02
Remove misc.rs (#491)
Put everything that was in `misc.rs` into their own files, with some opportunistic
refactoring, because why not.
2019-10-09 01:40:40 -07:00
Casey Rodarmor
ca4f2a44ed
Refactor run::run and Config (#490)
Improve color parsing, add `ConfigError`, put `invocation_directory` on Config object, return error code from `run::run` instead of exiting.
2019-10-09 00:18:53 -07:00
Casey Rodarmor
ab11740104
Add explicit Subcommand enum (#484) 2019-10-07 04:04:39 -07:00
Casey Rodarmor
2938ab1561
Start pulling argument parsing out of run::run() (#483)
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.
2019-10-07 02:06:45 -07:00
Casey Rodarmor
2818d4da1c
Fix summary feature conditional compilation (#475)
The correct syntax is `#[cfg(feature = "summary")]`.
2019-09-23 18:52:27 -07:00
Casey Rodarmor
1d063cce01
Hide summary functionality behind feature flag (#472)
Since summaries are only used by Janus, the Just ecosystem testing tool,
it makes sense to hide it behind a feature flag.
2019-09-21 19:19:56 -07:00
Casey Rodarmor
1230af138c
Add context to deprecation warnings (#473)
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.
2019-09-21 18:53:30 -07:00
Casey Rodarmor
1cb90f4e65
Use pub(crate) instead of pub (#471)
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.
2019-09-21 15:35:03 -07:00
Casey Rodarmor
74e45e7c05
Remove dependency on brev (#462)
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.
2019-07-13 01:55:06 -07:00
Rostyslav Shevtsiv
7f06bc68d4 Ignore file name case while searching for justfile (#436) 2019-06-01 22:38:02 -07:00
Casey Rodarmor
9c82a1e329
Move CompilationErrorKind into separate module (#416) 2019-04-19 02:40:25 -07:00
Casey Rodarmor
415c84ea39
Refactor and rename test macros (#415) 2019-04-19 02:17:43 -07:00
Casey Rodarmor
596ea34460
Replace regex-based lexer with character-at-a-time lexer (#406) 2019-04-15 22:40:02 -07:00
Casey Rodarmor
12f9428695
Add justfile summaries (#399)
Exposes an interface for producing a summary that captures the important details of the parsed justfile.
2019-04-11 16:35:16 -07:00
Casey Rodarmor
3a287b864a
Housekeeping (#394)
- Upgrade to rust 2018
- Update dependencies
- Use BTree{Map,Set} instead of Map and Set
2019-04-11 15:23:14 -07:00
ryloric
f64f07a0cc Add recipe aliases (#390)
Recipe aliases may be defined with `alias f = foo`, allowing recipes to be called by shorter names on the command line.
2019-04-11 12:30:29 -07:00
Geoff Shannon
6b0fc174d8 Fuzz test compiler (#362) 2018-10-13 19:12:35 +09:00
Casey Rodarmor
2b6b715528
Refactor Everything (#250) 2017-11-16 23:30:08 -08:00
Casey Rodarmor
86dc82f548
Give errors clearer names (#249) 2017-11-16 13:26:01 -08:00
Casey Rodarmor
3acd56646f
Stop empty comments from swallowing the next line (#247) 2017-11-15 12:53:01 -08:00
Casey Rodarmor
b9e1f73919
Make unexpected token formatting clearer (#243)
Symbols are now be surrounded by single quotes, to set them off more
clearly.
2017-11-14 13:03:26 -08:00
Casey Rodarmor
8fa91a4eb1 Hide recipes with names starting with an _ from --list and --sumamary (#229) 2017-10-06 23:48:07 -07:00
Casey Rodarmor
e22da124d4 Update dependencies (#225)
Thanks @chrisvittal for reporting!
2017-09-10 17:28:00 -07:00
Casey Rodarmor
1fd1c05653 Retire warn! in favor of eprintln! (#218) 2017-08-18 14:15:43 -07:00
Casey Rodarmor
1b1a155dda Refactor color handling (#204)
Color logic is fairly complicated, so moved it into its own
module.

A `Color` object now encapsulates the --color setting, which
stream we are printing to, and what color we are painting.

This way, Color::paint can just do the right thing when asked to
paint text.

Also added tests to make sure that --list and --highlight colors
are using the correct color codes.
2017-06-01 18:01:35 -07:00
Casey Rodarmor
98fe09f26b Fix lints and things that make clippy sad (#199) 2017-05-12 22:09:47 -04:00
Casey Rodarmor
4a35c14024 Set up cross platform continuous integration on travis (#191)
Gets travis cross platform testing working.

Based on the templates from:

japaric/trust/commit/29b0e084ff2c40d1aa1b6a5d66ab81eca90439e1
2017-05-07 22:48:07 -04:00
Casey Rodarmor
616d324cd7 Error if running default recipe that requires arguments (#194) 2017-05-07 15:11:10 -07:00
Casey Rodarmor
7f2d360231 Write argument_range() in terms of min_arguments() and max_arguments() (#193) 2017-05-07 14:45:23 -07:00
Casey Rodarmor
1990c58a21 Add option to highlight echoed recipe lines (#190)
Using bold and cyan, for visibility.
2017-04-25 23:39:34 -07:00
Casey Rodarmor
165e7951af Use cygpath to translate paths on windows (#188)
I was previous doing it manually, which failed when running in
powershell in a Github Desktop for windows.

Use the `cygpath` utility instead.
2017-04-23 16:09:34 -07:00
Casey Rodarmor
832cf7b357 Move output() and OutputError into brev (#187)
They're pretty generic and generally useful, so move them into brev on crates.io.
2017-04-23 15:37:17 -07:00
Casey Rodarmor
af764f5eab Refactor RunError::Backtick* to use OutputError (#186)
Add `output()` to get stdout of a command, return a OutputError if
it failes. Refactor backtick run errors to contain an OutputError.
2017-04-23 14:21:21 -07:00
Casey Rodarmor
84a55da1ce Make shebangs work on windows (#185)
We use EXEPATH, which points to the root of the MinGW installation
and can be used as a base for translating the unix path to the
executable in the shebang line.

If we're not on MinGW, well, we just throw up our hands and hope
for the best.
2017-04-22 21:39:29 -07:00
Casey Rodarmor
6a0e3abb32 Improve shebang execution error message (#184)
I was reusing TmpdirIoError for a few cases, but one of them
usually has more to do with the contents of the shebang line than
an actual io error involving the tmpdir. Pull it out into its own
RunError variant and improve the message.
2017-04-22 19:05:51 -07:00
Casey Rodarmor
b0c5fa23ee Multi shell integration tests (#181)
* Run integration tests on multiple shells

To make sure that I don't break tests for shells other than my
dev-box's `sh` and the `sh` on travis, each integration test case
now runs using `sh`, `dash`, and `bash.
2017-04-22 16:15:15 -07:00
Casey Rodarmor
2b294f0b30 Create platform module (#178)
Moves platform specific functionality into its own module.

Thanks to @Meralis40 for starting this!

This also gets just building on windows \^_^/

Although a lot of tests still fail (✖╭╮✖)

The `PlatformInterface` trait contains functions which abstract
over platform specific functionality, with implementations for
different platforms behind #[cfg(*)] attributes.

- `make_shebang_command()` constructs a command which will execute
  the given script as if by a shebang. On linux this executes the
  file, on windows it runs the interpreter directly.

- `set_execute_permission()` sets the execute permission on a
  file. This is a nop on windows, since all files are executable.

- `signal_from_exit_status()` extracts the signal a process was
  halted by from its exit status, if it was halted by a signal.
2017-04-21 22:20:13 -07:00
Casey Rodarmor
6a26c72131 Use libc::{EXIT_SUCCESS, EXIT_FAILURE} for status (#177) 2017-04-21 22:11:18 -07:00
Casey Rodarmor
c9ce4601b9 Add --shell option to specify the shell to use (#175)
Mostly for debugging purposes, so I can make sure behavior is
consistent across different shells. Although I suppose this might
also be of use if you've got a mega weird `sh` that you'd like to
avoid.

Defaults to `sh` so current behavior is preserved.
2017-04-20 23:06:03 -07:00
Casey Rodarmor
435b4c5ea3 Remove trailing whitespace (#167) 2017-04-02 20:39:23 -07:00
Casey Rodarmor
b6b01bf6d4 🔥 Disallow names that start with '-' (#154)
This is done for two reasons:

1. Such names cannot be given on the command line, since clap will
intercept them and wrongly interpret them as flags.

2. The name '---' can conflict with yaml document delimiters. Kind of
speculative, but I was thinking that it would be nice to make sure that
'---' and '...' are illegal in a justfile, so that that one can be
included in a yaml document stream. Is this silly? I am really not sure.

This is backwards incompatible, but I don't think anyone will notice,
since names that start with '-' are likely to be rare.
2017-02-10 20:15:25 -08:00
Casey Rodarmor
bed28c1df5 Resolve dependencies after the first (#149)
The recipe dependency resolver had a bug which caused it to not resolve
dependencies after the first.

This caused the parameter check later in the program to crash.

Added a test and fixed it.

Fixes #148.
2017-01-18 20:32:55 -08:00
Casey Rodarmor
1befc8674e Test all errors and error messages (#145) 2017-01-08 19:01:48 -08:00
Casey Rodarmor
64e4905e49 Capitalize all error messages (#144) 2017-01-08 17:26:34 -08:00
Casey Rodarmor
c6256333ed Lift limitations on recipes that take parameters (#137)
Previously, only one recipe with parameters could be passed on the
command line. This was to avoid confusion in case the number of
parameters a recipe took changed, and wound up using as an argument was
was once a recipe.

However, I don't think this is actually particularly confusing in
practice, and could be a slightly annoying limitation.

Now, any number of recipes with parameters may be given on the command
line.

Fixes #70
2016-12-10 16:35:52 -08:00