Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Implement `add` command. | bbb2544bd06f29866465d651c32ca4d6e017f5e9 | Jan Allersma | 2018-12-11 15:43:10 |
Implement `exe` command. | 1eaa36242201cf7ade5f23a14340e630c267db07 | Jan Allersma | 2018-12-11 13:23:32 |
Implement `run` and `build` commands. | 14e9e25b6a06f587c1a50829e72c829ae59a87c2 | Jan Allersma | 2018-12-10 20:57:08 |
Implement non-recursive dependency check. | 5ffd40604755d1c2dde9353c74f06a006deea33c | Jan Allersma | 2018-12-07 20:50:42 |
Restructure project. | c2d98caf7897e87284fb2891e1d4b92d14cf37e1 | Jan Allersma | 2018-12-06 16:20:46 |
Initial commit. | 4c152d55edc20ac55fd749a2b32b204134a664e3 | Jan Allersma | 2018-12-05 17:03:08 |
File | Lines added | Lines deleted |
---|---|---|
src/backend/add.rs | 58 | 0 |
src/backend/check.rs | 1 | 1 |
src/backend/config.rs | 14 | 0 |
src/backend/filesystem.rs | 1 | 1 |
src/backend/mod.rs | 1 | 0 |
src/backend/project.rs | 5 | 4 |
src/main.rs | 6 | 0 |
File src/backend/add.rs added (mode: 100644) (index 0000000..e2e1222) | |||
1 | extern crate serde_json; | ||
2 | |||
3 | use std::env; | ||
4 | use std::result::Result; | ||
5 | use std::path::PathBuf; | ||
6 | |||
7 | pub fn add(args: &mut env::Args) -> Result<String, String> { | ||
8 | let dep_dir: PathBuf; | ||
9 | |||
10 | let dep_name = match args.next() { | ||
11 | Some(name) => name, | ||
12 | None => return Err(String::from("Missing dependency name!")) | ||
13 | }; | ||
14 | |||
15 | match super::filesystem::get_dep_root() { | ||
16 | Ok(mut dir) => { | ||
17 | dir.push(dep_name.clone()); | ||
18 | dep_dir = dir; | ||
19 | }, | ||
20 | Err(e) => return Err(e.to_string()) | ||
21 | } | ||
22 | |||
23 | if dep_dir.exists() { | ||
24 | return Err(String::from("Dependency already exists.")) | ||
25 | } | ||
26 | |||
27 | let mut args: String = args.into_iter().map(|arg| arg + " ").collect(); | ||
28 | |||
29 | match args.pop() { | ||
30 | Some(_) => update_module(dep_name, args), | ||
31 | None => update_module(dep_name, String::new()) | ||
32 | } | ||
33 | } | ||
34 | |||
35 | fn update_module(key: String, value: String) -> Result<String, String> { | ||
36 | let path: PathBuf; | ||
37 | let config: serde_json::Value; | ||
38 | |||
39 | match super::filesystem::get_module_root() { | ||
40 | Some(p) => path = p, | ||
41 | None => return Err(String::from("No config file in module found.")) | ||
42 | } | ||
43 | |||
44 | match super::config::get_json(path.clone()) { | ||
45 | Ok(mut json) => { | ||
46 | json["deps"]["linux"][key.clone()] = json!(value); | ||
47 | json["deps"]["os-x"][key.clone()] = json!(value); | ||
48 | json["deps"]["windows"][key] = json!(value); | ||
49 | config = json.clone(); | ||
50 | }, | ||
51 | Err(e) => return Err(e) | ||
52 | } | ||
53 | |||
54 | match super::config::update(path, config) { | ||
55 | Ok(_) => Ok(String::from("Dependency added!")), | ||
56 | Err(e) => Err(e) | ||
57 | } | ||
58 | } |
File src/backend/check.rs changed (mode: 100644) (index 260e822..571c6a8) | |||
... | ... | pub fn dep(config: serde_json::Value) -> Result<String, String> { | |
126 | 126 | } | } |
127 | 127 | ||
128 | 128 | fn dir_check(dependency: String, command: String) -> Result<String, String> { | fn dir_check(dependency: String, command: String) -> Result<String, String> { |
129 | let dir = super::filesystem::get_dep_dir(); | ||
129 | let dir = super::filesystem::get_dep_root(); | ||
130 | 130 | ||
131 | 131 | match dir { | match dir { |
132 | 132 | Ok(mut dep_dir) => { | Ok(mut dep_dir) => { |
File src/backend/config.rs changed (mode: 100644) (index 20ae5d1..9a5c8b1) | |||
... | ... | pub fn create(mut path: PathBuf) -> Result<(), Error> { | |
38 | 38 | Ok(()) | Ok(()) |
39 | 39 | } | } |
40 | 40 | ||
41 | pub fn update(mut path: PathBuf, value: serde_json::Value) -> Result<(), String> { | ||
42 | path.push("beheer.json"); | ||
43 | |||
44 | match File::create(path) { | ||
45 | Ok(mut file) => { | ||
46 | match file.write_all(serde_json::to_string_pretty(&value).unwrap().as_bytes()) { | ||
47 | Ok(_) => Ok(()), | ||
48 | Err(e) => Err(e.to_string()) | ||
49 | } | ||
50 | }, | ||
51 | Err(e) => Err(e.to_string()) | ||
52 | } | ||
53 | } | ||
54 | |||
41 | 55 | fn read(mut path: PathBuf) -> Result<String, String> { | fn read(mut path: PathBuf) -> Result<String, String> { |
42 | 56 | let mut config = String::new(); | let mut config = String::new(); |
43 | 57 |
File src/backend/filesystem.rs changed (mode: 100644) (index 7b57573..fd33d13) | |||
... | ... | pub fn get_project_root() -> Option<path::PathBuf> { | |
38 | 38 | } | } |
39 | 39 | } | } |
40 | 40 | ||
41 | pub fn get_dep_dir() -> Result<path::PathBuf> { | ||
41 | pub fn get_dep_root() -> Result<path::PathBuf> { | ||
42 | 42 | match get_project_root() { | match get_project_root() { |
43 | 43 | Some(mut path) => { | Some(mut path) => { |
44 | 44 | path.push("dep"); | path.push("dep"); |
File src/backend/mod.rs changed (mode: 100644) (index 4b4da8d..7601bdb) | |||
1 | pub mod add; | ||
1 | 2 | pub mod config; | pub mod config; |
2 | 3 | pub mod project; | pub mod project; |
3 | 4 | pub mod filesystem; | pub mod filesystem; |
File src/backend/project.rs changed (mode: 100644) (index c772de1..093e329) | |||
... | ... | pub fn help() { | |
91 | 91 | println!("--help -h\t\tShow this message"); | println!("--help -h\t\tShow this message"); |
92 | 92 | println!(""); | println!(""); |
93 | 93 | ||
94 | println!("init [DIRECTORY]\tInitialize new project in specified directory. Defaults to current directory."); | ||
95 | println!("build\t\t\tBuild current project."); | ||
96 | println!("run [ARGUMENTS]\t\tBuild and run current project with ARGUMENTS to run project with."); | ||
97 | println!("exe [ARGUMENTS]\t\tRun current project with ARGUMENTS. The project won't be built."); | ||
94 | println!("init [DIRECTORY]\t\tInitialize new project in specified directory. Defaults to current directory."); | ||
95 | println!("build\t\t\t\tBuild current project."); | ||
96 | println!("run [ARGUMENTS]\t\t\tBuild and run current project with ARGUMENTS to run project with."); | ||
97 | println!("exe [ARGUMENTS]\t\t\tRun current project with ARGUMENTS. The project won't be built."); | ||
98 | println!("add NAME COMMAND [ARGUMENTS]\tAdd dependency with NAME to module and is built through COMMAND with ARGUMENTS."); | ||
98 | 99 | } | } |
File src/main.rs changed (mode: 100644) (index a1a3bd1..58a7dd2) | |||
... | ... | fn parse() { | |
44 | 44 | Err(e) => println!("Running project failed: {}", e) | Err(e) => println!("Running project failed: {}", e) |
45 | 45 | } | } |
46 | 46 | } | } |
47 | else if &argument == "add" { | ||
48 | match backend::add::add(&mut argv) { | ||
49 | Ok(msg) => println!("{}", msg), | ||
50 | Err(e) => println!("Could not add dependency: {}", e) | ||
51 | } | ||
52 | } | ||
47 | 53 | }, | }, |
48 | 54 | None => backend::project::help() | None => backend::project::help() |
49 | 55 | } | } |