Commit Graph

143 Commits

Author SHA1 Message Date
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
Casey Rodarmor
af543d7258 Remove duplicate return (#136) 2016-12-10 16:31:38 -08:00
Casey Rodarmor
11c0d349db Collapse unnecessary block (#128) 2016-11-18 07:07:20 -08:00
Casey Rodarmor
1ac5b4ea42 Add variadic parameters (#127)
Recipes may now have a final variadic parameter:

```make
foo bar+:
  @echo {{bar}}
```

Variadic parameters accept one or more arguments, and expand to a string containing those arguments separated by spaces:

```sh
$ just foo a b c d e
a b c d e
```

I elected to accept one or more arguments instead of zero or more arguments since unexpectedly empty arguments can sometimes be dangerous. 

```make
clean dir:
  rm -rf {{dir}}/bin
```

If `dir` is empty in the above recipe, you'll delete `/bin`, which is probably not what was intended.
2016-11-18 07:03:34 -08:00
Casey Rodarmor
cef117f8bd Report line number in recipe failure messages (#125)
The grammar now permits blank lines in recipes.

Note that inside of recipes, the token `NEWLINE` is used instead of the
non-terminal `eol`. This is because an `eol` optionally includes a
comment, whereas inside recipes bodies comments get no special
treatment.
2016-11-16 22:18:55 -08:00
Casey Rodarmor
07634d9390 Fix line numbers (#124)
Blank lines were being ignored by the parser, so lines would be reported
incorrectly in error messages from shebang recipes. Blank lines are now
included by the parser, so shebang recipes expand to have the non-blank
lines in the expected place in the file.
2016-11-16 21:37:43 -08:00
Casey Rodarmor
2f4bcc57bc Add --verbose flag (#123)
Causes all recipe lines to be printed, regardless of --quiet or `@`.
Prints the name of each recipe before running it. Hopefully useful for
diagnosing problems.
2016-11-16 21:06:51 -08:00
Casey Rodarmor
133b4a2ada Renames: Parser::file and just::parse (#122)
Parser::file -> Parser::justfile
just::parse -> just::compile

Also get rid of super::, super::std
2016-11-16 20:17:24 -08:00
Casey Rodarmor
e628378dbb Avoid using panic! outside of tests (#121)
Don't panic.
2016-11-15 20:39:56 -08:00
Casey Rodarmor
10c377b88c Allow ' raw strings to contain literal newlines (#107)
Fixes #8
2016-11-13 14:04:20 -08:00
Casey Rodarmor
2b81dc2b76 Fix spurious circular dependency error (#102)
The resolver.seen() needs to be cleared between recipes.

Also add push recipe for creating branches on github without needing to
create one locally.
2016-11-13 00:01:42 -08:00
Casey Rodarmor
26bfef4a2f Add doc comments to recipes (#101)
If a `#...` comment appears on the line immediately before a recipe, it
is considered to be a doc comment for that recipe.

Doc comments will be printed when recipes are `--list`ed or `--dump`ed.

Also adds some color to the `--list`ing.

Fixes #84
2016-11-12 23:31:19 -08:00
Casey Rodarmor
112462ec62 Toggle meaning of '@' on recipes prefixed with '@' (#100)
Fixes #65
2016-11-12 16:12:00 -08:00
Casey Rodarmor
babe97bf0d Allow line continuations in plain recipes with '\' (#99)
Some ugly code, but not as bad as I thought.

Elected not to go with indentation based line continuations. Too many
weird edge cases and feels like a gratuitious incompatibility with make.

Fixes #9
2016-11-12 15:45:12 -08:00
Casey Rodarmor
5b2d671c1d Get rid of mostly unused Justfile.recipes() (#98) 2016-11-12 14:43:47 -08:00
Casey Rodarmor
1856646a9c Error -> CompileError (#97)
Fixes #43
2016-11-12 14:24:33 -08:00
Casey Rodarmor
7cfc37f647 Line up names in --evaluate (#93)
Fixes #66
2016-11-12 13:12:43 -08:00
Casey Rodarmor
3d8d901968 Suggest alternatives to uknown recipes (#91)
Kind of silly, but why not. Will only suggest an alternative if edit
distance is less than 3. This could probably increase if the names are
longer.
2016-11-12 12:36:12 -08:00
Casey Rodarmor
6e8289c624 Make --list print recipes with arguments (#88)
Added `--summary` which just prints recipe names, like `--list` previous
to this change.

Fixes #75
2016-11-12 11:40:52 -08:00
Casey Rodarmor
7e3859ef18 Fix needless borrow clippy lints (#81) 2016-11-12 09:33:38 -08:00
Casey Rodarmor
ff2ca9b30c Improve missing parameter panic message (#79)
Returning an InternalError in a map() is hard, so just panic, but give a
decent error message.
2016-11-12 09:24:52 -08:00
Casey Rodarmor
886acf2f95 Let recipes take default arguments (#77)
Looks like this:

```make
recipe argument default-argument='default value':
  echo argument is {{argument}}
  echo default-argument is {{default-argument}}
```

Thanks @deckarep for the feature request!

Fixes #49
2016-11-12 09:15:13 -08:00
Casey Rodarmor
5663cb61a6 Use ...? instead of try!(...) (#72)
See https://blog.rust-lang.org/2016/11/10/Rust-1.13.html for more info.

Huge diff, but all tests still pass, so yolo.
2016-11-11 21:37:16 -08:00
Casey Rodarmor
510a269d00 Remove unnecessary lifetimes (#58)
Thanks clippy!
2016-11-11 19:12:44 -08:00
Casey Rodarmor
ac7634000e Fix error messages with wide character
Input may contain tabs and other characters whose byte widths do not
correspond to their display widths. This causes error context
underlining to be off when lines contain those characters

Fixed by properly accounting for the display width of characters, as
well as replacing tabs with spaces when printing error messages.
2016-11-11 17:32:35 -08:00
Casey Rodarmor
4d20ffeac4 Use colors in output
This is a pretty gross commit, since it also includes a lot of
unrelated refactoring, especially of how error messages are printed.

Also adds a lint recipe that prints lines over 100 characters

To test, I added a `--color=[auto|always|never]` option that defaults to
auto in normal use, but can be forced to `always` for testing. In `auto`
mode it defers to `atty` to figure out if the current stream is a
terminal and uses color if so.

Color printing is controlled by the `alternate` formatting flag.

When printing an error message, using `{:#}` will print it with colors
and `{}` will print it normally.
2016-11-11 17:32:35 -08:00
Casey Rodarmor
6b888bbfe4 Fix off by one error in backtick error message (#52)
I was using the width of the index of the line, not the displayed line
number, which is the index + 1, which could cause the error message to
be misaligned.

Fixed it, and added a test that checks for this.
2016-11-11 17:15:16 -08:00
Casey Rodarmor
74fa6d4962 Include line in all error messages (#51)
I had previously not included the line for some error messages, but I
don't think that I had a good reason why, and they look pretty good,
so adding them back for consistency.
2016-11-11 17:09:51 -08:00
Casey Rodarmor
2bc55ba815 Improve a few error messages (#47)
Surround variables with backticks, capitalize first letter of error
message, inflect properly depending on number of unknown overrides, and
improve wording.

Also added build dependency to `filter` recipe.
2016-11-11 14:33:17 -08:00
Casey Rodarmor
e4d35a8270 Add --quiet/-q flag to supress all output (#17)
This is for avoiding writing to stderr during tests,
although it's a nice option so it feels worth exposing
to users.
2016-11-05 01:01:43 -07:00
Casey Rodarmor
599cc80f86 Move all run options into a struct (#16)
In preparation for adding a --quiet flag, since the number of parameters
to run is getting a bit silly.
2016-11-05 00:31:38 -07:00
Casey Rodarmor
9f2568c461 Fix tab-indented lines in shebang recipes
Fixed a precedence bug in the recipe parser where tab-indented
lines in a shebang recipe would trigger an ExtraLeadingWhitespace
error.
2016-11-02 22:02:29 -07:00
Casey Rodarmor
cef8b4fbdf Updated readme 2016-10-31 21:53:31 -07:00
Casey Rodarmor
7f6a74af24 Rename arguments to parameters. 2016-10-31 19:11:27 -07:00
Casey Rodarmor
9e9b525369 Bump version to 0.2.11 and rename back to just 2016-10-30 18:12:59 -07:00
Casey Rodarmor
1290c5a8bd Added raw '' strings 2016-10-30 16:56:22 -07:00
Casey Rodarmor
2568e949b5 Cleaned up export parsing 2016-10-30 16:34:39 -07:00
Casey Rodarmor
69f8e07a30 export variables done 2016-10-30 16:15:18 -07:00
Casey Rodarmor
f925520101 Use BTreeMap and BTreeSet as Map and Set 2016-10-30 14:37:03 -07:00
Casey Rodarmor
cc683cbb04 Bump version, add --debug 2016-10-30 13:14:39 -07:00
Casey Rodarmor
9a368fb351 variable=value overrides done 2016-10-30 03:08:28 -07:00
Casey Rodarmor
25c6432fa3 Backtick tests done! 2016-10-30 01:27:05 -07:00
Casey Rodarmor
9118d39903 Remove unnecessary return 2016-10-30 00:25:04 -07:00
Casey Rodarmor
980c5d0b33 Backticks implemented. Error messages still suck though. 2016-10-30 00:20:29 -07:00
Casey Rodarmor
8b149b66fc Panic commit. 2016-10-29 23:39:12 -07:00
Casey Rodarmor
3d3c4394c2 Ready to actually implement backtick evaluation 2016-10-29 22:56:47 -07:00
Casey Rodarmor
70e9d4e653 Refactoring. Checkpoint commit. 2016-10-29 21:51:39 -07:00
Casey Rodarmor
810365f22b Add assignment resolving 2016-10-29 20:39:21 -07:00
Casey Rodarmor
70d1df5b9c Working on backticks. They are evaluated as strings for now. 2016-10-29 01:58:30 -07:00
Casey Rodarmor
b57b84e550 Arguments done! 2016-10-29 00:55:47 -07:00
Casey Rodarmor
ac5433248e Arguments working but still ugly 2016-10-29 00:14:41 -07:00
Casey Rodarmor
58fb70e16e Surround tokens with `` in errors 2016-10-28 20:40:16 -07:00
Casey Rodarmor
0f29b4fc2a Pretty errors with underlined tokens! 2016-10-28 20:34:25 -07:00
Casey Rodarmor
a55adafa60 Notes 2016-10-28 19:56:33 -07:00
Casey Rodarmor
383754d2fb More tests 2016-10-28 19:38:32 -07:00
Casey Rodarmor
3c80f7f7ae Add '--debug' flag to print justfile with evaluated expressions and
variables
2016-10-28 16:41:46 -07:00
Casey Rodarmor
01df3d5e4a Add {:#} format printing to justfile for --show 2016-10-28 16:32:13 -07:00
Casey Rodarmor
a8a5c342e7 More integration tests 2016-10-28 15:59:50 -07:00
Casey Rodarmor
1d74432dd1 Remove stray comment 2016-10-28 00:14:50 -07:00
Casey Rodarmor
ec41eaf0e7 Bump version, use variable for quine text 2016-10-28 00:10:19 -07:00
Casey Rodarmor
0a16803247 Clippy fixes, bump version 0.2.3, string escapes 2016-10-28 00:06:36 -07:00
Casey Rodarmor
fa2fae5fb8 Clean up code, rename Token.class -> Token.kind 2016-10-27 18:48:55 -07:00
Casey Rodarmor
dd824ef364 Test that evaluated recipe lines are correct
Saves the value in each expression fragment when that fragment is
evaluated so that we can print the value in Display. This allows
us to check fragment values in tests.
2016-10-27 18:01:07 -07:00
Casey Rodarmor
4bb926abc4 line evaluation is done 2016-10-27 09:44:07 -07:00
Casey Rodarmor
ebd4186452 Added missing arguments error whenever we try to run an recipe with
arguments, since arguments are unsupported.
2016-10-27 00:31:50 -07:00
Casey Rodarmor
d5f81dc0b4 Parsing and tokenizing tests are now mostly passsing, not running
recipes though.
2016-10-27 00:13:10 -07:00
Casey Rodarmor
aae665a4e9 Tokenize looks like it's working. 2016-10-26 22:04:12 -07:00
Casey Rodarmor
7a77c910b6 Reworked tokenizer, not trying to dig myself out of the wreckage. 2016-10-26 20:54:44 -07:00
Casey Rodarmor
52aa496d9c Lots of work. Expression parsing and evaluation mostly. 2016-10-25 19:11:58 -07:00
Casey Rodarmor
9aed7ca129 Handle line interpolation parsing 2016-10-23 23:38:49 -07:00
Casey Rodarmor
f74ece6629 Ran clippy and fixed issues. I <3 clippy! 2016-10-23 20:39:50 -07:00
Casey Rodarmor
e8a4a82e4d TokenClass -> TokenKind
'Kind' seems to be the rust convention, or close too it. See
std::io::ErrorKind and compiler internals.
2016-10-23 18:46:04 -07:00
Casey Rodarmor
acc97a4eba Reached feature parity with new parser 2016-10-23 16:43:52 -07:00
Casey Rodarmor
913bcba5f7 Starting to rewrite the parser 2016-10-22 23:18:26 -07:00
Casey Rodarmor
3b92e00ee7 Comment out everything to rewrite parser 2016-10-22 19:36:54 -07:00
Casey Rodarmor
4c44096718 Giant fucking mess. 2016-10-16 18:59:49 -07:00
Casey Rodarmor
e5efa3f7d5 Make dependencies execute in order they appear
It doesn't seem particularly valuable for dependencies to execute in any
order, so make Recipe.dependencies a vec so they execute in order.
2016-10-09 00:30:33 -07:00
Casey Rodarmor
71a4359188 Support for polyglot recipes! 2016-10-08 17:29:45 -07:00
Casey Rodarmor
6df4109510 More validation of recipes, allow leading shebang 2016-10-08 17:29:45 -07:00
Casey Rodarmor
b5cac00ffc Invoke sh with -u (error on unbound variable) 2016-10-08 17:29:45 -07:00
Casey Rodarmor
bd8b12db93 Don't print double newline for --show 2016-10-08 17:29:45 -07:00
Casey Rodarmor
b11b81c640 Add --show command line flag 2016-10-08 17:29:45 -07:00
Casey Rodarmor
c957165f4c Actually run recipes, add a bunch of tests 2016-10-08 17:29:45 -07:00
Casey Rodarmor
c0f58eefe8 Lots of work. 2016-10-03 23:55:55 -07:00
Casey Rodarmor
0c29b55df6 Split into lib.rs and main.rs, wrote a bunch of tests 2016-10-02 22:30:28 -07:00