1
1
mirror of https://github.com/casey/just.git synced 2024-09-11 05:55:31 +03:00

Initial commit. Broken.

This commit is contained in:
Casey Rodarmor 2016-06-16 17:13:43 -07:00
commit a0d5b83a80
5 changed files with 97 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

4
Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[root]
name = "j"
version = "0.1.0"

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "j"
version = "0.1.0"
authors = ["Casey Rodarmor <casey@rodarmor.com>"]
[dependencies]

2
justfile Normal file
View File

@ -0,0 +1,2 @@
default:
cargo run hello -- -- bar a b c

84
src/main.rs Normal file
View File

@ -0,0 +1,84 @@
use std::io::prelude::*;
fn can(command: &str) -> bool {
if let Ok(paths) = std::env::var("PATH") {
for path in paths.split(":") {
let candidate = format!("{}/{}", path, command);
if isfile(&candidate) {
return true;
}
}
}
false
}
fn isfile(path: &str) -> bool {
if let Ok(metadata) = std::fs::metadata(path) {
metadata.is_file()
} else {
false
}
}
fn cwd() -> String {
match std::env::current_dir() {
Ok(pathbuf) => pathbuf.to_str().unwrap_or_else(|| panic!("cwd: cwd was not a valid utf8 string")).to_string(),
Err(err) => panic!("cwd: {}", err),
}
}
fn cd(path: &str) {
if let Err(err) = std::env::set_current_dir(path) {
panic!("cd: {}", err)
}
}
fn say(s: &str) {
println!("{}", s)
}
fn warn(s: &str) {
if let Err(err) = std::io::stderr().write(s.as_bytes()) {
panic!("warn: could not write to stderr: {}", err);
}
if let Err(err) = std::io::stderr().write("\n".as_bytes()) {
panic!("warn: could not write to stderr: {}", err);
}
}
fn die(s: &str) {
warn(s);
std::process::exit(-1);
}
fn main() {
let can_make = can("make");
let can_gmake = can("gmake");
if !(can_make || can_gmake) {
die("cannot find \"make\" or \"gmake\" in $PATH");
}
println!("can make: {}", can_make);
println!("can gmake: {}", can_gmake);
loop {
if isfile("justfile") {
break;
}
if cwd() == "/" {
die("No justfile found.")
}
cd("..");
}
let recipes: Vec<String> = std::env::args().skip(1).take_while(|arg| arg != "--").collect();
let arguments: Vec<String> = std::env::args().skip(1 + recipes.len() + 1).collect();
print!("{:?}", recipes);
print!("{:?}", arguments);
// export as $ARG0 -> ARGX
// start at 0 or 1?
// exec $MAKE MAKEFLAGS='' --always-make --no-print-directory -f justfile ${RECIPES[*]}
}