List of commits:
Subject Hash Author Date (UTC)
Restructure project. c2d98caf7897e87284fb2891e1d4b92d14cf37e1 Jan Allersma 2018-12-06 16:20:46
Initial commit. 4c152d55edc20ac55fd749a2b32b204134a664e3 Jan Allersma 2018-12-05 17:03:08
Commit c2d98caf7897e87284fb2891e1d4b92d14cf37e1 - Restructure project.
Author: Jan Allersma
Author date (UTC): 2018-12-06 16:20
Committer name: Jan Allersma
Committer date (UTC): 2018-12-06 16:20
Parent(s): 4c152d55edc20ac55fd749a2b32b204134a664e3
Signing key:
Tree: a3d7b5b97820852f2e873f7849da7ce2bafdf0ee
File Lines added Lines deleted
src/arguments/config/mod.rs 0 23
src/arguments/mod.rs 0 45
src/backend/build.rs 12 0
src/backend/check.rs 99 0
src/backend/config.rs 53 0
src/backend/fetch.rs 7 0
src/backend/filesystem.rs 0 0
src/backend/mod.rs 6 0
src/backend/project.rs 41 0
src/main.rs 28 4
File src/arguments/config/mod.rs deleted (index 7edf8e1..0000000)
1 use std::io::{Result, Error, ErrorKind, Write};
2 use std::fs::File;
3 use std::path::PathBuf;
4
5 pub fn create(mut path: PathBuf) -> Result<()> {
6 let content = json!({
7 "project-name": path.file_name().unwrap().to_str().unwrap(),
8 "version": 0.1
9 });
10
11 path.push("beheer.json");
12
13 match File::open(path.to_str().unwrap()) {
14 Ok(_) => return Err(Error::new(ErrorKind::AlreadyExists, "Already found a 'beheer.json' file.")),
15 Err(_) => {
16 match File::create(path) {
17 Ok(mut file) => file.write_all(content.to_string().as_bytes())?,
18 Err(e) => return Err(e)
19 }
20 }
21 }
22 Ok(())
23 }
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/build.rs added (mode: 100644) (index 0000000..d75299f)
1 use std::io::Result;
2
3 pub fn build(config: String) -> Result<String> {
4 println!("Building project..");
5
6 match super::check::dep(config) {
7 Ok(result) => println!("{}", result),
8 Err(e) => return Err(e)
9 }
10
11 Ok(String::from("Build succeeded!"))
12 }
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/fetch.rs added (mode: 100644) (index 0000000..6160248)
1 use std::process::Command;
2
3 pub fn fetch(dep: String, command: String) {
4 let out = Command::new(command).output().expect("");
5
6 println!("{:#?}", out.stderr);
7 }
File src/backend/filesystem.rs renamed from src/filesystem.rs (similarity 100%)
File src/backend/mod.rs added (mode: 100644) (index 0000000..4b4da8d)
1 pub mod config;
2 pub mod project;
3 pub mod filesystem;
4 pub mod build;
5 pub mod check;
6 pub mod fetch;
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 } }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/kapstok/NHL-Beheer

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/kapstok/NHL-Beheer

Clone this repository using git:
git clone git://git.rocketgit.com/user/kapstok/NHL-Beheer

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main