|
|
@ -1,17 +1,29 @@
|
|
1
|
|
use std::os;
|
|
|
1
|
#![feature(rust_2018_preview)]
|
|
2
|
2
|
|
|
3
|
|
fn main() {
|
|
4
|
|
let path = Path::new(os::args().get(1).as_slice());
|
|
5
|
|
let mut cwd = Path::new("");
|
|
6
|
|
while cwd != Path::new("/") {
|
|
7
|
|
cwd = os::getcwd();
|
|
8
|
|
if path.exists() {
|
|
9
|
|
println!("{}", cwd.display());
|
|
10
|
|
return;
|
|
11
|
|
} else {
|
|
12
|
|
os::change_dir(&Path::new(".."));
|
|
13
|
|
}
|
|
14
|
|
}
|
|
|
3
|
use std::env;
|
|
|
4
|
use std::path::PathBuf;
|
|
|
5
|
use std::process;
|
|
15
|
6
|
|
|
16
|
|
os::set_exit_status(1);
|
|
|
7
|
// Checks if it can find a directory (or file) up the directory tree.
|
|
|
8
|
//
|
|
|
9
|
// Can be used to check if you're in a vcs-versioned directory, like git, mercurial or svn.
|
|
|
10
|
//
|
|
|
11
|
// usage: up .git
|
|
|
12
|
// up .git <path-to-directory>
|
|
|
13
|
fn main() {
|
|
|
14
|
let repo_dir_name = &env::args().nth(1).expect("missing argument");
|
|
|
15
|
let mut path = env::args()
|
|
|
16
|
.nth(2)
|
|
|
17
|
.map(PathBuf::from)
|
|
|
18
|
.ok_or(0)
|
|
|
19
|
.or_else(|_| env::current_dir())
|
|
|
20
|
.unwrap();
|
|
|
21
|
while path.parent().is_some() {
|
|
|
22
|
if path.join(repo_dir_name).exists() {
|
|
|
23
|
println!("{}", path.canonicalize().unwrap().display());
|
|
|
24
|
return;
|
|
|
25
|
}
|
|
|
26
|
path = path.parent().unwrap().to_path_buf();
|
|
|
27
|
}
|
|
|
28
|
process::exit(1);
|
|
17
|
29
|
}
|