List of commits:
Subject Hash Author Date (UTC)
Initial commit. 4c152d55edc20ac55fd749a2b32b204134a664e3 Jan Allersma 2018-12-05 17:03:08
Commit 4c152d55edc20ac55fd749a2b32b204134a664e3 - Initial commit.
Author: Jan Allersma
Author date (UTC): 2018-12-05 17:03
Committer name: Jan Allersma
Committer date (UTC): 2018-12-05 17:03
Parent(s):
Signing key:
Tree: c7bd104928242fe61272a9a63289270e4d5cb46b
File Lines added Lines deleted
.gitignore 3 0
Cargo.lock 37 0
Cargo.toml 7 0
README.md 1 0
src/arguments/config/mod.rs 23 0
src/arguments/mod.rs 45 0
src/filesystem.rs 38 0
src/main.rs 14 0
File .gitignore added (mode: 100644) (index 0000000..8741fe0)
1 /target
2 **/*.rs.bk
3 *beheer.json
File Cargo.lock added (mode: 100644) (index 0000000..fdbf543)
1 [[package]]
2 name = "beheer"
3 version = "0.1.0"
4 dependencies = [
5 "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
6 ]
7
8 [[package]]
9 name = "itoa"
10 version = "0.4.3"
11 source = "registry+https://github.com/rust-lang/crates.io-index"
12
13 [[package]]
14 name = "ryu"
15 version = "0.2.7"
16 source = "registry+https://github.com/rust-lang/crates.io-index"
17
18 [[package]]
19 name = "serde"
20 version = "1.0.80"
21 source = "registry+https://github.com/rust-lang/crates.io-index"
22
23 [[package]]
24 name = "serde_json"
25 version = "1.0.33"
26 source = "registry+https://github.com/rust-lang/crates.io-index"
27 dependencies = [
28 "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
29 "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
30 "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
31 ]
32
33 [metadata]
34 "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
35 "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
36 "checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef"
37 "checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811"
File Cargo.toml added (mode: 100644) (index 0000000..56011b3)
1 [package]
2 name = "beheer"
3 version = "0.1.0"
4 authors = ["Jan Allersma <jan@allersma.be>"]
5
6 [dependencies]
7 serde_json = "1.0"
File README.md added (mode: 100644) (index 0000000..3f087ab)
1 # Beheer
File src/arguments/config/mod.rs added (mode: 100644) (index 0000000..7edf8e1)
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 added (mode: 100644) (index 0000000..26ddd0f)
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/filesystem.rs added (mode: 100644) (index 0000000..e61a3c6)
1 use std::{path, env};
2
3 fn get_root (mut path: path::PathBuf) -> Option<path::PathBuf> {
4 loop {
5 let mut config = path.clone();
6 config.push("beheer.json");
7
8 if config.as_path().is_file() {
9 return Some(path);
10 }
11
12 if !path.pop() {
13 return None;
14 }
15 }
16 }
17
18 pub fn get_module_root() -> Option<path::PathBuf> {
19 get_root(env::current_dir().unwrap())
20 }
21
22 pub fn get_project_root() -> Option<path::PathBuf> {
23 let mut path = get_root(env::current_dir().unwrap());
24 let mut parentdir = path.clone();
25
26 loop {
27 match parentdir {
28 Some(mut p) => {
29 path = Some(path::PathBuf::from(p.clone()));
30 if !p.pop() {
31 return path;
32 }
33 parentdir = get_root(p);
34 },
35 None => return path
36 }
37 }
38 }
File src/main.rs added (mode: 100644) (index 0000000..74833f9)
1 #[macro_use]
2 extern crate serde_json;
3
4 mod filesystem;
5 mod arguments;
6
7 fn main() {
8 match filesystem::get_project_root() {
9 Some(_) => println!("You are in a project."),
10 None => println!("You are not in a project.")
11 }
12
13 arguments::parse();
14 }
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