File src/backend/add.rs changed (mode: 100644) (index 61efc0e..2713beb) |
... |
... |
pub fn add(args: &Vec<String>) -> Result<String, String> { |
33 |
33 |
} |
} |
34 |
34 |
|
|
35 |
35 |
fn update_module(key: String, value: String) -> Result<String, String> { |
fn update_module(key: String, value: String) -> Result<String, String> { |
36 |
|
let path: PathBuf; |
|
|
36 |
|
let mut path: PathBuf; |
37 |
37 |
let config: serde_json::Value; |
let config: serde_json::Value; |
38 |
38 |
|
|
39 |
39 |
match super::filesystem::get_current_module_root() { |
match super::filesystem::get_current_module_root() { |
|
... |
... |
fn update_module(key: String, value: String) -> Result<String, String> { |
41 |
41 |
None => return Err(String::from("No config file in module found.")) |
None => return Err(String::from("No config file in module found.")) |
42 |
42 |
} |
} |
43 |
43 |
|
|
44 |
|
match super::config::get_json_from_dir(path.clone()) { |
|
|
44 |
|
path.push("ambassade.json"); |
|
45 |
|
|
|
46 |
|
match super::config::get_json(&path) { |
45 |
47 |
Ok(mut json) => { |
Ok(mut json) => { |
46 |
48 |
json["deps"]["linux"][key.clone()] = json!(value); |
json["deps"]["linux"][key.clone()] = json!(value); |
47 |
49 |
json["deps"]["os-x"][key.clone()] = json!(value); |
json["deps"]["os-x"][key.clone()] = json!(value); |
|
... |
... |
fn update_module(key: String, value: String) -> Result<String, String> { |
51 |
53 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
52 |
54 |
} |
} |
53 |
55 |
|
|
54 |
|
match super::config::update(path, config) { |
|
|
56 |
|
match super::config::update(&path, config) { |
55 |
57 |
Ok(_) => Ok(String::from("Dependency added!")), |
Ok(_) => Ok(String::from("Dependency added!")), |
56 |
58 |
Err(e) => Err(e) |
Err(e) => Err(e) |
57 |
59 |
} |
} |
File src/backend/build.rs changed (mode: 100644) (index d7d87e8..41102be) |
... |
... |
extern crate serde_json; |
2 |
2 |
|
|
3 |
3 |
use std::result::Result; |
use std::result::Result; |
4 |
4 |
use std::path::PathBuf; |
use std::path::PathBuf; |
5 |
|
use std::env; |
|
6 |
5 |
|
|
7 |
|
pub fn build(config_file: PathBuf) -> Result<String, String> { |
|
8 |
|
let config; |
|
|
6 |
|
pub fn build(dep_name: String) -> Result<String, String> { |
|
7 |
|
let dep_path = match super::filesystem::search_current_module_root(dep_name.clone()) { |
|
8 |
|
Ok(path) => path, |
|
9 |
|
Err(e) => return Err(e.to_string()) |
|
10 |
|
}; |
9 |
11 |
|
|
10 |
|
match super::config::get_json_from_dir(config_file) { |
|
11 |
|
Ok(result) => config = result, |
|
|
12 |
|
let config_path = match super::dep_config::scan(dep_name) { |
|
13 |
|
Ok(path) => path, |
12 |
14 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
13 |
|
} |
|
|
15 |
|
}; |
|
16 |
|
|
|
17 |
|
let config = match super::config::get_json(&config_path) { |
|
18 |
|
Ok(json) => json, |
|
19 |
|
Err(e) => return Err(e) |
|
20 |
|
}; |
14 |
21 |
|
|
15 |
22 |
match super::dep::check(config.clone()) { |
match super::dep::check(config.clone()) { |
16 |
23 |
Ok(result) => println!("{}", result), |
Ok(result) => println!("{}", result), |
17 |
24 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
18 |
25 |
} |
} |
19 |
26 |
|
|
20 |
|
match build_module(config) { |
|
|
27 |
|
match build_module(dep_path, config) { |
21 |
28 |
Ok(result) => println!("{}", result), |
Ok(result) => println!("{}", result), |
22 |
29 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
23 |
30 |
} |
} |
|
... |
... |
pub fn build_rec(config_file: PathBuf) -> Result<String, String> { |
45 |
52 |
} |
} |
46 |
53 |
|
|
47 |
54 |
println!("Building current project '{}'..", &dep_tree.name); |
println!("Building current project '{}'..", &dep_tree.name); |
48 |
|
match build(dep_tree.path) { |
|
|
55 |
|
match build(dep_tree.name) { |
49 |
56 |
Ok(result) => println!("{}", result), |
Ok(result) => println!("{}", result), |
50 |
57 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
51 |
58 |
} |
} |
|
... |
... |
pub fn build_rec(config_file: PathBuf) -> Result<String, String> { |
54 |
61 |
} |
} |
55 |
62 |
|
|
56 |
63 |
#[cfg(target_os="linux")] |
#[cfg(target_os="linux")] |
57 |
|
fn build_module(config: serde_json::Value) -> Result<String, String> { |
|
|
64 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
58 |
65 |
println!("Building module.."); |
println!("Building module.."); |
59 |
66 |
|
|
60 |
|
let build_cmd = &config["build"]["linux"]; |
|
|
67 |
|
let build_cmd = &config_value["build"]["linux"]; |
61 |
68 |
|
|
62 |
69 |
if !build_cmd.is_string() { |
if !build_cmd.is_string() { |
63 |
70 |
return Err(String::from("ambassade.json: 'build->linux' should be a string.")); |
return Err(String::from("ambassade.json: 'build->linux' should be a string.")); |
64 |
71 |
} |
} |
65 |
72 |
|
|
66 |
|
super::fetch::build(env::current_dir().unwrap(), String::from(build_cmd.as_str().unwrap())) |
|
|
73 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
67 |
74 |
} |
} |
68 |
75 |
|
|
69 |
76 |
#[cfg(target_os="macos")] |
#[cfg(target_os="macos")] |
70 |
|
fn build_module(config: serde_json::Value) -> Result<String, String> { |
|
|
77 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
71 |
78 |
println!("Building module.."); |
println!("Building module.."); |
72 |
79 |
|
|
73 |
|
let build_cmd = &config["build"]["os-x"]; |
|
|
80 |
|
let build_cmd = &config_value["build"]["os-x"]; |
74 |
81 |
|
|
75 |
82 |
if !build_cmd.is_string() { |
if !build_cmd.is_string() { |
76 |
83 |
return Err(String::from("ambassade.json: 'build->os-x' should be a string.")); |
return Err(String::from("ambassade.json: 'build->os-x' should be a string.")); |
77 |
84 |
} |
} |
78 |
85 |
|
|
79 |
|
super::fetch::fetch(env::get_current_dir().unwrap(), String::from(build_cmd.as_str().unwrap())) |
|
|
86 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
80 |
87 |
} |
} |
81 |
88 |
|
|
82 |
89 |
#[cfg(target_os="windows")] |
#[cfg(target_os="windows")] |
83 |
|
fn build_module(config: serde_json::Value) -> Result<String, String> { |
|
|
90 |
|
fn build_module(config_path: PathBuf, config_value: serde_json::Value) -> Result<String, String> { |
84 |
91 |
println!("Building module.."); |
println!("Building module.."); |
85 |
92 |
|
|
86 |
|
let build_cmd = &config["build"]["windows"]; |
|
|
93 |
|
let build_cmd = &config_value["build"]["windows"]; |
87 |
94 |
|
|
88 |
95 |
if !build_cmd.is_string() { |
if !build_cmd.is_string() { |
89 |
96 |
return Err(String::from("ambassade.json: 'build->windows' should be a string.")); |
return Err(String::from("ambassade.json: 'build->windows' should be a string.")); |
90 |
97 |
} |
} |
91 |
98 |
|
|
92 |
|
super::fetch::fetch(env::get_current_dir().unwrap(), String::from(build_cmd.as_str().unwrap())) |
|
|
99 |
|
super::fetch::build(config_path, String::from(build_cmd.as_str().unwrap())) |
93 |
100 |
} |
} |
File src/backend/filesystem.rs changed (mode: 100644) (index 5190c5f..e3e8889) |
1 |
|
use std::{path, env, fs}; |
|
|
1 |
|
use std::{path, env, fs, result}; |
2 |
2 |
use std::io::{Result, Error, ErrorKind}; |
use std::io::{Result, Error, ErrorKind}; |
3 |
3 |
|
|
4 |
4 |
fn get_root(mut path: path::PathBuf) -> Option<path::PathBuf> { |
fn get_root(mut path: path::PathBuf) -> Option<path::PathBuf> { |
|
... |
... |
pub fn get_dep_root(from_dir: path::PathBuf) -> Result<path::PathBuf> { |
67 |
67 |
} |
} |
68 |
68 |
} |
} |
69 |
69 |
|
|
|
70 |
|
pub fn search_current_module_root(dep_name: String) -> result::Result<path::PathBuf, String> { |
|
71 |
|
search_module_root(dep_name, env::current_dir().unwrap()) |
|
72 |
|
} |
|
73 |
|
|
|
74 |
|
pub fn search_module_root(dep_name: String, from_dir: path::PathBuf) -> result::Result<path::PathBuf, String> { |
|
75 |
|
let project_path = match get_project_root(from_dir.clone()) { |
|
76 |
|
Some(path) => path, |
|
77 |
|
None => return Err(String::from("No project folder found!")) |
|
78 |
|
}; |
|
79 |
|
|
|
80 |
|
if dep_name == String::from(project_path.file_name().unwrap().to_str().unwrap()) { |
|
81 |
|
return Ok(project_path); |
|
82 |
|
} |
|
83 |
|
|
|
84 |
|
match get_dep_root(from_dir) { |
|
85 |
|
Ok(mut dir) => { |
|
86 |
|
dir.push(dep_name); |
|
87 |
|
Ok(dir) |
|
88 |
|
}, |
|
89 |
|
Err(e) => Err(e.to_string()) |
|
90 |
|
} |
|
91 |
|
} |
|
92 |
|
|
70 |
93 |
pub fn get_dep_config_root() -> Result<path::PathBuf> { |
pub fn get_dep_config_root() -> Result<path::PathBuf> { |
71 |
94 |
match get_current_project_root() { |
match get_current_project_root() { |
72 |
95 |
Some(mut path) => { |
Some(mut path) => { |
File src/backend/project.rs changed (mode: 100644) (index a42a6b6..22b03b2) |
... |
... |
pub fn build<I>(args: &mut I) -> Result<String, String> where I: Iterator<Item=S |
19 |
19 |
match args.next() { |
match args.next() { |
20 |
20 |
Some(ref module) if module.as_str() == "--module" => { |
Some(ref module) if module.as_str() == "--module" => { |
21 |
21 |
match super::filesystem::get_current_module_root() { |
match super::filesystem::get_current_module_root() { |
22 |
|
Some(dir) => super::build::build(dir), |
|
|
22 |
|
Some(dir) => { |
|
23 |
|
let dep_name = String::from(dir.file_name().unwrap().to_str().unwrap()); |
|
24 |
|
super::build::build(dep_name) |
|
25 |
|
}, |
23 |
26 |
None => Err(String::from("not in a project (sub)directory.")) |
None => Err(String::from("not in a project (sub)directory.")) |
24 |
27 |
} |
} |
25 |
28 |
}, |
}, |
|
... |
... |
pub fn delete<I>(path: &mut I) -> Result<String, String> where I: Iterator<Item= |
96 |
99 |
} |
} |
97 |
100 |
|
|
98 |
101 |
pub fn add(args: &Vec<String>) -> Result<String, String> { |
pub fn add(args: &Vec<String>) -> Result<String, String> { |
99 |
|
let mut path: String = match args.get(0) { |
|
|
102 |
|
let mut dep: String = match args.get(0) { |
100 |
103 |
Some(arg) => arg.clone(), |
Some(arg) => arg.clone(), |
101 |
|
None => return Err(String::from("Missing path as argument.")) |
|
|
104 |
|
None => return Err(String::from("Missing dependency name as argument.")) |
102 |
105 |
}; |
}; |
103 |
106 |
|
|
104 |
107 |
match super::filesystem::get_current_module_root() { |
match super::filesystem::get_current_module_root() { |
105 |
108 |
Some(dir) => { |
Some(dir) => { |
106 |
|
match super::git::ignore::add(&mut dir.clone(), &mut path) { |
|
|
109 |
|
match super::git::ignore::add(&mut dir.clone(), &mut dep) { |
107 |
110 |
Ok(_) => {}, |
Ok(_) => {}, |
108 |
111 |
Err(e) => return Err(e) |
Err(e) => return Err(e) |
109 |
112 |
} |
} |
|
... |
... |
pub fn add(args: &Vec<String>) -> Result<String, String> { |
124 |
127 |
} |
} |
125 |
128 |
} |
} |
126 |
129 |
|
|
127 |
|
pub fn ignore(args: &Vec<String>) -> Result<(), String> { |
|
128 |
|
let mut entry: String = args.get(0).unwrap().clone(); |
|
|
130 |
|
pub fn hide(args: &Vec<String>) -> Result<String, String> { |
|
131 |
|
match add(args) { |
|
132 |
|
Ok(msg) => println!("{}", msg), |
|
133 |
|
Err(e) => return Err(e) |
|
134 |
|
} |
129 |
135 |
|
|
130 |
|
match super::filesystem::get_current_dep_root() { |
|
131 |
|
Ok(mut dir) => { |
|
132 |
|
dir.push(&entry); |
|
133 |
|
super::git::ignore::add(&mut dir, &mut entry) // entry moet "ambassade.json" worden. |
|
134 |
|
}, |
|
135 |
|
Err(e) => Err(e.to_string()) |
|
|
136 |
|
let dep: String = match args.get(0) { |
|
137 |
|
Some(arg) => arg.clone(), |
|
138 |
|
None => return Err(String::from("Missing dep name.")) |
|
139 |
|
}; |
|
140 |
|
|
|
141 |
|
match super::dep_config::init(dep.clone()) { |
|
142 |
|
Ok(_) => println!("Created '{}.json' in 'dep_config' folder.", dep), |
|
143 |
|
Err(e) => return Err(e) |
136 |
144 |
} |
} |
|
145 |
|
|
|
146 |
|
Ok(String::from("dependency successfully hidden!")) |
137 |
147 |
} |
} |
138 |
148 |
|
|
139 |
149 |
pub fn dep_tree<I>(args: &mut I) -> Result<deptree::Node, String> where I: Iterator<Item=String> { |
pub fn dep_tree<I>(args: &mut I) -> Result<deptree::Node, String> where I: Iterator<Item=String> { |
File src/parser.rs changed (mode: 100644) (index 9d1a6ea..2415cd8) |
... |
... |
fn parse<I>(args: &mut I, open_shell: bool) -> bool where I: Iterator<Item=Strin |
50 |
50 |
} |
} |
51 |
51 |
else if argument == "hide" { |
else if argument == "hide" { |
52 |
52 |
let args: Vec<String> = args.collect(); |
let args: Vec<String> = args.collect(); |
53 |
|
match backend::project::add(&args) { |
|
|
53 |
|
match backend::project::hide(&args) { |
54 |
54 |
Ok(msg) => println!("{}", msg), |
Ok(msg) => println!("{}", msg), |
55 |
|
Err(e) => println!("Could not add dependency: {}", e) |
|
56 |
|
} |
|
57 |
|
|
|
58 |
|
match backend::project::ignore(&args) { |
|
59 |
|
Ok(_) => println!("DONE! Dependency hidden."), |
|
60 |
55 |
Err(e) => println!("Could not hide dependency: {}", e) |
Err(e) => println!("Could not hide dependency: {}", e) |
61 |
56 |
} |
} |
62 |
57 |
} |
} |