Updated readme

This commit is contained in:
Casey Rodarmor 2016-10-31 21:53:31 -07:00
parent ca9a0b7bff
commit cef8b4fbdf
5 changed files with 105 additions and 43 deletions

View File

@ -9,13 +9,13 @@ Commands are stored in a file called `justfile` with a syntax inspired by `make`
```make ```make
test-all: build test-all: build
./test --all ./test --all
test TEST: build test TEST: build
./test --test {{TEST}} ./test --test {{TEST}}
build: build:
cc *.c -o main cc *.c -o main
``` ```
`just` produces detailed error messages and avoids `make`'s idiosyncrasies, so debugging a justfile is easier and less suprising than debugging a makefile. `just` produces detailed error messages and avoids `make`'s idiosyncrasies, so debugging a justfile is easier and less suprising than debugging a makefile.
@ -44,10 +44,10 @@ Recipes look like this:
```make ```make
recipe-name: recipe-name:
echo 'This is a recipe!' echo 'This is a recipe!'
another-recipe: another-recipe:
@echo 'Another recipe.' @echo 'Another recipe.'
``` ```
Running `just` with no arguments runs the first recipe in the `justfile`: Running `just` with no arguments runs the first recipe in the `justfile`:
@ -73,22 +73,22 @@ Recipes stop running if a command fails. Here `cargo publish` will only run if `
```make ```make
publish: publish:
cargo test cargo test
# tests passed, time to publish! # tests passed, time to publish!
cargo publish cargo publish
``` ```
Recipes can depend on other recipes. Here the `test` recipe depends on the `build` recipe, so `build` will run before `test`: Recipes can depend on other recipes. Here the `test` recipe depends on the `build` recipe, so `build` will run before `test`:
```make ```make
build: build:
cc main.c foo.c bar.c -o main cc main.c foo.c bar.c -o main
test: build: test: build
./test ./test
sloc: sloc:
@echo "`wc -l *.c` lines of code" @echo "`wc -l *.c` lines of code"
``` ```
```sh ```sh
@ -123,20 +123,20 @@ tardir = "awesomesauce-" + version
tarball = tardir + ".tar.gz" tarball = tardir + ".tar.gz"
publish: publish:
rm -f {{tarball}} rm -f {{tarball}}
mkdir {{tardir}} mkdir {{tardir}}
cp README.md *.c {{tardir}} cp README.md *.c {{tardir}}
tar zcvf {{tarball}} {{tardir}} tar zcvf {{tarball}} {{tardir}}
scp {{tarball}} me@server.com:release/ scp {{tarball}} me@server.com:release/
rm -rf {{tarball}} {{tardir}} rm -rf {{tarball}} {{tardir}}
``` ```
Recipes may take arguments. Here recipe `build` takes an argument called `target`: Recipes may take arguments. Here recipe `build` takes an argument called `target`:
```make ```make
build target: build target:
@echo 'Building {{target}}...' @echo 'Building {{target}}...'
cd {{target}} && make cd {{target}} && make
``` ```
Only one recipe that takes arguments may given on the command line, and other recipes may not depend on it. To pass arguments put them after the recipe name: Only one recipe that takes arguments may given on the command line, and other recipes may not depend on it. To pass arguments put them after the recipe name:
@ -153,17 +153,17 @@ Variables can be exported to recipes as environment variables:
export RUST_BACKTRACE = "1" export RUST_BACKTRACE = "1"
test: test:
# will print a stack trace if it crashes # will print a stack trace if it crashes
cargo test cargo test
``` ```
Backticks can be used to store the result of commands: Backticks can be used to store the result of commands:
```make ```make
localhost = `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g' localhost = `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`
serve: serve:
./serve {{localhost}} 8080 ./serve {{localhost}} 8080
``` ```
@ -173,25 +173,25 @@ Recipes that start with a `#!` are executed as scripts, so you can write recipes
polyglot: python js perl sh ruby polyglot: python js perl sh ruby
python: python:
#!/usr/bin/env python3 #!/usr/bin/env python3
print('Hello from python!') print('Hello from python!')
js: js:
#!/usr/bin/env node #!/usr/bin/env node
console.log('Greetings from JavaScript!') console.log('Greetings from JavaScript!')
perl: perl:
#!/usr/bin/env perl #!/usr/bin/env perl
print "Larry Wall says Hi!\n"; print "Larry Wall says Hi!\n";
sh: sh:
#!/usr/bin/env sh #!/usr/bin/env sh
hello='Yo' hello='Yo'
echo "$hello from a shell script!" echo "$hello from a shell script!"
ruby: ruby:
#!/usr/bin/env ruby #!/usr/bin/env ruby
puts "Hello from ruby!" puts "Hello from ruby!"
``` ```
```sh ```sh
@ -248,13 +248,26 @@ A description of the grammar of justfiles can be found in [](grammar.md).
Before `just` was a bloated rust program it was a tiny shell script. If you would rather not or can't install rust you can find the old shellscript in [](extras/just.sh). This version uses `make`, so it may not be portable across systems. Before `just` was a bloated rust program it was a tiny shell script. If you would rather not or can't install rust you can find the old shellscript in [](extras/just.sh). This version uses `make`, so it may not be portable across systems.
### non-project specific justfile
If you want some commands to be available everwhere, put them in `~/.justfile` and add the following to your shell's initialization file:
```sh
alias .j='just --justfile ~/.justfile --working-directory ~'
```
Or, if you'd rather they run in the current directory:
```
alias .j='just --justfile ~/.justfile --working-directory .'
```
further ramblings further ramblings
----------------- -----------------
`just` is a trivial program, but I personally find it very useful to write a `justfile` for almost every project, big or small. `just` is a trivial program, but I personally find it very useful to write a `justfile` for almost every project, big or small.
On a big projects with multiple contributers, it's very useful to have a file with all the commands needed to work on the project close at hand. On a big projects with multiple contributers, it's very useful to have a file with all the commands needed to work on the project close at hand.
There are probably different commands to test, build, lint, deploy, and the like, and having them all in one place is useful and cuts down on the time you have to spend telling people which commands to run and how to type them. There are probably different commands to test, build, lint, deploy, and the like, and having them all in one place is useful and cuts down on the time you have to spend telling people which commands to run and how to type them.

4
notes
View File

@ -1,10 +1,6 @@
todo todo
---- ----
- extract anything between ``` in readme as a justfile and make sure it parses
. alias .j='just --justfile ~/.justfile --working-directory ~'
- try to get some users - try to get some users
. travis . travis
. recurse center . recurse center

View File

@ -1,5 +1,6 @@
extern crate tempdir; extern crate tempdir;
extern crate brev; extern crate brev;
extern crate regex;
use tempdir::TempDir; use tempdir::TempDir;
use super::std::process::Command; use super::std::process::Command;
@ -549,3 +550,28 @@ recipe:
"echo recipe \\\\\\\"\n", "echo recipe \\\\\\\"\n",
); );
} }
#[test]
fn line_error_spacing() {
integration_test(
&[],
r#"
???
"#,
255,
"",
"error: unknown start of token:
|
10 | ???
| ^
",
);
}

View File

@ -810,11 +810,12 @@ impl<'a> Display for Error<'a> {
match self.text.lines().nth(self.line) { match self.text.lines().nth(self.line) {
Some(line) => { Some(line) => {
let line_number_width = self.line.to_string().len(); let displayed_line = self.line + 1;
let line_number_width = displayed_line.to_string().len();
try!(write!(f, "{0:1$} |\n", "", line_number_width)); try!(write!(f, "{0:1$} |\n", "", line_number_width));
try!(write!(f, "{} | {}\n", self.line + 1, line)); try!(write!(f, "{} | {}\n", displayed_line, line));
try!(write!(f, "{0:1$} |", "", line_number_width)); try!(write!(f, "{0:1$} |", "", line_number_width));
try!(write!(f, " {0:1$}{2:^<3$}", "", self.column, "", self.width.unwrap_or(0))); try!(write!(f, " {0:1$}{2:^<3$}", "", self.column, "", self.width.unwrap_or(1)));
}, },
None => if self.index != self.text.len() { None => if self.index != self.text.len() {
try!(write!(f, "internal error: Error has invalid line number: {}", self.line + 1)) try!(write!(f, "internal error: Error has invalid line number: {}", self.line + 1))

View File

@ -1,4 +1,5 @@
extern crate tempdir; extern crate tempdir;
extern crate brev;
use super::{Token, Error, ErrorKind, Justfile, RunError}; use super::{Token, Error, ErrorKind, Justfile, RunError};
use super::TokenKind::*; use super::TokenKind::*;
@ -805,3 +806,28 @@ fn unknown_overrides() {
other => panic!("expected an code run error, but got: {}", other), other => panic!("expected an code run error, but got: {}", other),
} }
} }
#[test]
fn readme_test() {
let mut justfiles = vec![];
let mut current = None;
for line in brev::slurp("README.md").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 {
parse_success(&justfile);
}
}