File src/arguments/mod.rs deleted (index 26ddd0f..0000000) |
1 |
|
mod config; |
|
2 |
|
|
|
3 |
|
use std::env; |
|
4 |
|
|
|
5 |
|
pub fn parse() { |
|
6 |
|
let mut argv = env::args(); |
|
7 |
|
let _ = argv.next(); |
|
8 |
|
let arg = argv.next(); |
|
9 |
|
|
|
10 |
|
match arg { |
|
11 |
|
Some(argument) => { |
|
12 |
|
if &argument == "--help" || &argument == "-h" { |
|
13 |
|
show_help(); |
|
14 |
|
} |
|
15 |
|
else if &argument == "init" { |
|
16 |
|
init(&mut argv); |
|
17 |
|
} |
|
18 |
|
}, |
|
19 |
|
None => show_help() |
|
20 |
|
} |
|
21 |
|
} |
|
22 |
|
|
|
23 |
|
fn show_help() { |
|
24 |
|
println!("Syntax:"); |
|
25 |
|
println!("$ beheer [FLAG] [COMMAND [ARGUMENTS]]"); |
|
26 |
|
println!(""); |
|
27 |
|
|
|
28 |
|
println!("--help -h\t\tShow this message"); |
|
29 |
|
println!(""); |
|
30 |
|
|
|
31 |
|
println!("init [DIRECTORY]\tInitialize new project in specified directory. Defaults to current directory."); |
|
32 |
|
} |
|
33 |
|
|
|
34 |
|
fn init(args: &mut env::Args) { |
|
35 |
|
let mut directory = env::current_dir().unwrap(); |
|
36 |
|
|
|
37 |
|
if let Some(projectname) = args.next() { |
|
38 |
|
directory.push(&projectname); |
|
39 |
|
} |
|
40 |
|
|
|
41 |
|
match config::create(directory) { |
|
42 |
|
Ok(_) => println!("Initialized project!"), |
|
43 |
|
Err(e) => println!("Initializing project failed: {}", e) |
|
44 |
|
} |
|
45 |
|
} |
|
File src/backend/check.rs added (mode: 100644) (index 0000000..6885a45) |
|
1 |
|
extern crate serde_json; |
|
2 |
|
|
|
3 |
|
use std::io::{Result, Error, ErrorKind, Write}; |
|
4 |
|
|
|
5 |
|
pub fn dep(config: String) -> Result<String> { |
|
6 |
|
let config_json: serde_json::Value; |
|
7 |
|
|
|
8 |
|
println!("Checking dependencies.."); |
|
9 |
|
|
|
10 |
|
match serde_json::from_str(&config) { |
|
11 |
|
Ok(json) => config_json = json, |
|
12 |
|
Err(e) => { |
|
13 |
|
let mut error = String::from("JSON ERROR! "); |
|
14 |
|
error.push_str(&e.line().to_string()); |
|
15 |
|
error.push(':'); |
|
16 |
|
error.push_str(&e.column().to_string()); |
|
17 |
|
error.push(' '); |
|
18 |
|
|
|
19 |
|
match e.classify() { |
|
20 |
|
serde_json::error::Category::Io => { |
|
21 |
|
error.push_str("Weird error...."); |
|
22 |
|
return Err(Error::new(ErrorKind::Other, error)); |
|
23 |
|
}, |
|
24 |
|
serde_json::error::Category::Syntax => { |
|
25 |
|
error.push_str("Syntax error in 'beheer.json'"); |
|
26 |
|
return Err(Error::new(ErrorKind::InvalidInput, error)); |
|
27 |
|
}, |
|
28 |
|
serde_json::error::Category::Data => { |
|
29 |
|
error.push_str("Semantic error in 'beheer.json'"); |
|
30 |
|
return Err(Error::new(ErrorKind::InvalidData, error)); |
|
31 |
|
}, |
|
32 |
|
serde_json::error::Category::Eof => { |
|
33 |
|
error.push_str("Unexpected end-of-file in 'beheer.json'"); |
|
34 |
|
return Err(Error::new(ErrorKind::UnexpectedEof, error)); |
|
35 |
|
} |
|
36 |
|
} |
|
37 |
|
} |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
pkg_check(config_json) |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
#[cfg(target_os="linux")] |
|
44 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
45 |
|
match config["deps"]["linux"] { |
|
46 |
|
json!(null) => return Ok(String::from("No dependencies found!")), |
|
47 |
|
ref deps => { |
|
48 |
|
if !deps.is_object() { |
|
49 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->linux' should be an object.")); |
|
50 |
|
} |
|
51 |
|
for dep in deps.as_object().unwrap().iter() { |
|
52 |
|
if !dep.1.is_string() { |
|
53 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
|
54 |
|
} |
|
55 |
|
println!("Checking for {}..\n\t{}", dep.0, dep.1); |
|
56 |
|
super::fetch::fetch(dep.0.to_string(), String::from(dep.1.as_str().unwrap())); |
|
57 |
|
} |
|
58 |
|
} |
|
59 |
|
} |
|
60 |
|
Ok(String::from("Dependencies OK!")) |
|
61 |
|
} |
|
62 |
|
|
|
63 |
|
#[cfg(target_os="macos")] |
|
64 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
65 |
|
match config["deps"]["os-x"] { |
|
66 |
|
json!(null) => return Ok(String::from("No dependencies found!")), |
|
67 |
|
ref sys_deps => { |
|
68 |
|
if !sys_deps.is_object() { |
|
69 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->os-x' should be an object.")); |
|
70 |
|
} |
|
71 |
|
for dep in sys_deps.as_object().unwrap().iter() { |
|
72 |
|
if !dep.1.is_string() { |
|
73 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
|
74 |
|
} |
|
75 |
|
println!("Checking for {} version {}..", dep.0, dep.1); |
|
76 |
|
} |
|
77 |
|
} |
|
78 |
|
} |
|
79 |
|
Ok(String::from("Dependencies OK!")) |
|
80 |
|
} |
|
81 |
|
|
|
82 |
|
#[cfg(target_os="windows")] |
|
83 |
|
fn pkg_check(config: serde_json::Value) -> Result<String> { |
|
84 |
|
match config["deps"]["windows"] { |
|
85 |
|
json!(null) => return Ok(String::from("No dependencies found!")), |
|
86 |
|
ref sys_deps => { |
|
87 |
|
if !sys_deps.is_object() { |
|
88 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: 'deps->windows' should be an object.")); |
|
89 |
|
} |
|
90 |
|
for dep in sys_deps.as_object().unwrap().iter() { |
|
91 |
|
if !dep.1.is_string() { |
|
92 |
|
return Err(Error::new(ErrorKind::InvalidData, "beheer.json: all deps should be strings!")); |
|
93 |
|
} |
|
94 |
|
println!("Checking for {} version {}..", dep.0, dep.1); |
|
95 |
|
} |
|
96 |
|
} |
|
97 |
|
} |
|
98 |
|
Ok(String::from("Dependencies OK!")) |
|
99 |
|
} |
File src/backend/config.rs added (mode: 100644) (index 0000000..28e0742) |
|
1 |
|
extern crate serde_json; |
|
2 |
|
|
|
3 |
|
use std::io::{Result, Error, ErrorKind, Write, Read}; |
|
4 |
|
use std::fs::File; |
|
5 |
|
use std::path::PathBuf; |
|
6 |
|
|
|
7 |
|
pub fn create(mut path: PathBuf) -> Result<()> { |
|
8 |
|
let content = json!({ |
|
9 |
|
"project-name": path.file_name().unwrap().to_str().unwrap(), |
|
10 |
|
"version": 0.1, |
|
11 |
|
"build": { |
|
12 |
|
"windows": "echo \"No build config set.\"", |
|
13 |
|
"os-x": "echo \"No build config set.\"", |
|
14 |
|
"linux": "echo \"No build config set.\"" |
|
15 |
|
}, |
|
16 |
|
"run": { |
|
17 |
|
"windows": "echo \"No run config set.\"", |
|
18 |
|
"os-x": "echo \"No run config set.\"", |
|
19 |
|
"linux": "echo \"No run config set.\"" |
|
20 |
|
} |
|
21 |
|
}); |
|
22 |
|
|
|
23 |
|
path.push("beheer.json"); |
|
24 |
|
|
|
25 |
|
match File::open(path.to_str().unwrap()) { |
|
26 |
|
Ok(_) => return Err(Error::new(ErrorKind::AlreadyExists, "Already found a 'beheer.json' file.")), |
|
27 |
|
Err(_) => { |
|
28 |
|
match File::create(path) { |
|
29 |
|
Ok(mut file) => { |
|
30 |
|
let content_str = serde_json::to_string_pretty(&content).unwrap(); |
|
31 |
|
file.write_all(content_str.as_bytes())?; |
|
32 |
|
}, |
|
33 |
|
Err(e) => return Err(e) |
|
34 |
|
} |
|
35 |
|
} |
|
36 |
|
} |
|
37 |
|
Ok(()) |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
pub fn read(mut path: PathBuf) -> Result<String> { |
|
41 |
|
let mut config = String::new(); |
|
42 |
|
|
|
43 |
|
path.push("beheer.json"); |
|
44 |
|
|
|
45 |
|
match File::open(path.to_str().unwrap()) { |
|
46 |
|
Ok(mut file) => { |
|
47 |
|
file.read_to_string(&mut config)?; |
|
48 |
|
}, |
|
49 |
|
Err(e) => return Err(e) |
|
50 |
|
} |
|
51 |
|
|
|
52 |
|
Ok(config) |
|
53 |
|
} |
File src/backend/project.rs added (mode: 100644) (index 0000000..38495ac) |
|
1 |
|
use std::env; |
|
2 |
|
use std::io::{Result, Error, ErrorKind}; |
|
3 |
|
|
|
4 |
|
pub fn init(args: &mut env::Args) { |
|
5 |
|
let mut directory = env::current_dir().unwrap(); |
|
6 |
|
|
|
7 |
|
if let Some(projectname) = args.next() { |
|
8 |
|
directory.push(&projectname); |
|
9 |
|
} |
|
10 |
|
|
|
11 |
|
match super::config::create(directory) { |
|
12 |
|
Ok(_) => println!("Initialized project!"), |
|
13 |
|
Err(e) => println!("Initializing project failed: {}", e) |
|
14 |
|
} |
|
15 |
|
} |
|
16 |
|
|
|
17 |
|
pub fn build() -> Result<String> { |
|
18 |
|
match super::filesystem::get_project_root() { |
|
19 |
|
Some(dir) => { |
|
20 |
|
match super::config::read(dir) { |
|
21 |
|
Ok(configfile) => return super::build::build(configfile), |
|
22 |
|
Err(e) => Err(e) |
|
23 |
|
} |
|
24 |
|
}, |
|
25 |
|
None => Err(Error::new(ErrorKind::NotFound, "not in a project (sub)directory.")) |
|
26 |
|
} |
|
27 |
|
} |
|
28 |
|
|
|
29 |
|
pub fn help() { |
|
30 |
|
println!("Syntax:"); |
|
31 |
|
println!("$ beheer [FLAG] [COMMAND [ARGUMENTS]]"); |
|
32 |
|
println!(""); |
|
33 |
|
|
|
34 |
|
println!("--help -h\t\tShow this message"); |
|
35 |
|
println!(""); |
|
36 |
|
|
|
37 |
|
println!("init [DIRECTORY]\tInitialize new project in specified directory. Defaults to current directory."); |
|
38 |
|
println!("build\t\t\tBuild current project."); |
|
39 |
|
println!("run [ARGUMENTS]\t\tBuild and run current project with ARGUMENTS to run project with."); |
|
40 |
|
println!("exe\t\t\tRun current project without building.", ); |
|
41 |
|
} |
File src/main.rs changed (mode: 100644) (index 74833f9..103a172) |
1 |
1 |
#[macro_use] |
#[macro_use] |
2 |
2 |
extern crate serde_json; |
extern crate serde_json; |
3 |
3 |
|
|
4 |
|
mod filesystem; |
|
5 |
|
mod arguments; |
|
|
4 |
|
mod backend; |
|
5 |
|
use std::env; |
6 |
6 |
|
|
7 |
7 |
fn main() { |
fn main() { |
8 |
|
match filesystem::get_project_root() { |
|
|
8 |
|
match backend::filesystem::get_project_root() { |
9 |
9 |
Some(_) => println!("You are in a project."), |
Some(_) => println!("You are in a project."), |
10 |
10 |
None => println!("You are not in a project.") |
None => println!("You are not in a project.") |
11 |
11 |
} |
} |
12 |
12 |
|
|
13 |
|
arguments::parse(); |
|
|
13 |
|
parse(); |
|
14 |
|
} |
|
15 |
|
|
|
16 |
|
fn parse() { |
|
17 |
|
let mut argv = env::args(); |
|
18 |
|
let _ = argv.next(); |
|
19 |
|
let arg = argv.next(); |
|
20 |
|
|
|
21 |
|
match arg { |
|
22 |
|
Some(argument) => { |
|
23 |
|
if &argument == "--help" || &argument == "-h" { |
|
24 |
|
backend::project::help(); |
|
25 |
|
} |
|
26 |
|
else if &argument == "init" { |
|
27 |
|
backend::project::init(&mut argv); |
|
28 |
|
} |
|
29 |
|
else if &argument == "build" { |
|
30 |
|
match backend::project::build() { |
|
31 |
|
Ok(result) => println!("{}", result), |
|
32 |
|
Err(e) => println!("Build failed: {}", e) |
|
33 |
|
} |
|
34 |
|
} |
|
35 |
|
}, |
|
36 |
|
None => backend::project::help() |
|
37 |
|
} |
14 |
38 |
} |
} |