mirror of
https://github.com/casey/just.git
synced 2024-11-23 02:44:56 +03:00
Updated readme
This commit is contained in:
parent
ca9a0b7bff
commit
cef8b4fbdf
85
README.md
85
README.md
@ -9,13 +9,13 @@ Commands are stored in a file called `justfile` with a syntax inspired by `make`
|
||||
|
||||
```make
|
||||
test-all: build
|
||||
./test --all
|
||||
./test --all
|
||||
|
||||
test TEST: build
|
||||
./test --test {{TEST}}
|
||||
./test --test {{TEST}}
|
||||
|
||||
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.
|
||||
@ -44,10 +44,10 @@ Recipes look like this:
|
||||
|
||||
```make
|
||||
recipe-name:
|
||||
echo 'This is a recipe!'
|
||||
echo 'This is a recipe!'
|
||||
|
||||
another-recipe:
|
||||
@echo 'Another recipe.'
|
||||
@echo 'Another recipe.'
|
||||
```
|
||||
|
||||
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
|
||||
publish:
|
||||
cargo test
|
||||
# tests passed, time to publish!
|
||||
cargo publish
|
||||
cargo test
|
||||
# tests passed, time to publish!
|
||||
cargo publish
|
||||
```
|
||||
|
||||
Recipes can depend on other recipes. Here the `test` recipe depends on the `build` recipe, so `build` will run before `test`:
|
||||
|
||||
```make
|
||||
build:
|
||||
cc main.c foo.c bar.c -o main
|
||||
cc main.c foo.c bar.c -o main
|
||||
|
||||
test: build:
|
||||
./test
|
||||
test: build
|
||||
./test
|
||||
|
||||
sloc:
|
||||
@echo "`wc -l *.c` lines of code"
|
||||
@echo "`wc -l *.c` lines of code"
|
||||
```
|
||||
|
||||
```sh
|
||||
@ -123,20 +123,20 @@ tardir = "awesomesauce-" + version
|
||||
tarball = tardir + ".tar.gz"
|
||||
|
||||
publish:
|
||||
rm -f {{tarball}}
|
||||
mkdir {{tardir}}
|
||||
cp README.md *.c {{tardir}}
|
||||
tar zcvf {{tarball}} {{tardir}}
|
||||
scp {{tarball}} me@server.com:release/
|
||||
rm -rf {{tarball}} {{tardir}}
|
||||
rm -f {{tarball}}
|
||||
mkdir {{tardir}}
|
||||
cp README.md *.c {{tardir}}
|
||||
tar zcvf {{tarball}} {{tardir}}
|
||||
scp {{tarball}} me@server.com:release/
|
||||
rm -rf {{tarball}} {{tardir}}
|
||||
```
|
||||
|
||||
Recipes may take arguments. Here recipe `build` takes an argument called `target`:
|
||||
|
||||
```make
|
||||
build target:
|
||||
@echo 'Building {{target}}...'
|
||||
cd {{target}} && make
|
||||
@echo 'Building {{target}}...'
|
||||
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:
|
||||
@ -153,17 +153,17 @@ Variables can be exported to recipes as environment variables:
|
||||
export RUST_BACKTRACE = "1"
|
||||
|
||||
test:
|
||||
# will print a stack trace if it crashes
|
||||
cargo test
|
||||
# will print a stack trace if it crashes
|
||||
cargo test
|
||||
```
|
||||
|
||||
Backticks can be used to store the result of commands:
|
||||
|
||||
```make
|
||||
localhost = `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'
|
||||
localhost = `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`
|
||||
|
||||
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
|
||||
|
||||
python:
|
||||
#!/usr/bin/env python3
|
||||
print('Hello from python!')
|
||||
#!/usr/bin/env python3
|
||||
print('Hello from python!')
|
||||
|
||||
js:
|
||||
#!/usr/bin/env node
|
||||
console.log('Greetings from JavaScript!')
|
||||
#!/usr/bin/env node
|
||||
console.log('Greetings from JavaScript!')
|
||||
|
||||
perl:
|
||||
#!/usr/bin/env perl
|
||||
print "Larry Wall says Hi!\n";
|
||||
#!/usr/bin/env perl
|
||||
print "Larry Wall says Hi!\n";
|
||||
|
||||
sh:
|
||||
#!/usr/bin/env sh
|
||||
hello='Yo'
|
||||
echo "$hello from a shell script!"
|
||||
#!/usr/bin/env sh
|
||||
hello='Yo'
|
||||
echo "$hello from a shell script!"
|
||||
|
||||
ruby:
|
||||
#!/usr/bin/env ruby
|
||||
puts "Hello from ruby!"
|
||||
#!/usr/bin/env ruby
|
||||
puts "Hello from ruby!"
|
||||
```
|
||||
|
||||
```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.
|
||||
|
||||
### 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
|
||||
-----------------
|
||||
|
||||
`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.
|
||||
|
||||
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
4
notes
@ -1,10 +1,6 @@
|
||||
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
|
||||
. travis
|
||||
. recurse center
|
||||
|
@ -1,5 +1,6 @@
|
||||
extern crate tempdir;
|
||||
extern crate brev;
|
||||
extern crate regex;
|
||||
|
||||
use tempdir::TempDir;
|
||||
use super::std::process::Command;
|
||||
@ -549,3 +550,28 @@ recipe:
|
||||
"echo recipe \\\\\\\"\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_error_spacing() {
|
||||
integration_test(
|
||||
&[],
|
||||
r#"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
???
|
||||
"#,
|
||||
255,
|
||||
"",
|
||||
"error: unknown start of token:
|
||||
|
|
||||
10 | ???
|
||||
| ^
|
||||
",
|
||||
);
|
||||
}
|
||||
|
@ -810,11 +810,12 @@ impl<'a> Display for Error<'a> {
|
||||
|
||||
match self.text.lines().nth(self.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, "{} | {}\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$}{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() {
|
||||
try!(write!(f, "internal error: Error has invalid line number: {}", self.line + 1))
|
||||
|
26
src/unit.rs
26
src/unit.rs
@ -1,4 +1,5 @@
|
||||
extern crate tempdir;
|
||||
extern crate brev;
|
||||
|
||||
use super::{Token, Error, ErrorKind, Justfile, RunError};
|
||||
use super::TokenKind::*;
|
||||
@ -805,3 +806,28 @@ fn unknown_overrides() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user