diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..161f3a0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# Crystal Linux Contributing Guidelines + +#### !! Always make sure to `git pull` before doing any work to avoid commit hell !! + +### Pre-Commit Checks + +- Make sure to `cargo fmt` your code before every commit push +- Unless in specific edge cases, don't push code that doesn't pass `cargo check` +- Try to correct any code with `cargo clippy` before you push + +### Formatting + +- UNIX line endings (LF instead of CRLF) +- 4 spaces per TAB + +### Good Practices + +- Try to use .unwrap() as little as possible +- Try to never use panic!() in production code, always try to have a possible way to resolve errors, even if it's just + unwrap_or/_else() +- Never use println!() or eprintln!() in finalised code. Using string functions (e.g. info() in Amethyst v3.0.0) is + preferred +- Compartmentalise as much as you can, avoid writing the exact same line of code 50 times if you can turn it into a + function + +### Examples of these guidelines in practice + +- https://git.getcryst.al/crystal/ame/src/branch/rewrite \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ba4c143 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +The Nolicense Revision 2.1 - Monday 15th November 2021 + +Copyright (c) 2022 Crystal Linux Team + +Everyone is permitted to freely copy and distribute this license document. Modified redistributions are subject to the +following license agreement. + +The Nolicense terms and conditions for copying, distribution and modification of software and any created assets are as +follows: + +- Any unmodified redistributions in either source code or binary form must retain this copyright notice in its entirety. + +- Any and all redistributions or derivative works, whether modified or unmodified, must credit the original author(s) of + the source code, and provide an easily accessible way to find the original author's source code, wherever it may be + published. + +- Derivative works and modified redistributions cannot be published under the same name as the original software, nor + can it be presented as an extension of or newer revision of said software, and unless explicitly permitted, the + original authors name(s) shall not be used to endorse said derivative works. + +This software is provided as-is; Neither the copyright holders nor any contributors to the software are to be held +liable for any damages caused by any files attached. By modifying or redistributing the software in any way, you +automatically agree to the terms of the license agreement. diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 3a4ebb9..4181caa 100755 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -1,2 +1,10 @@ -pub mod strings; +mod strings; pub mod structs; + +pub fn info(a: String) { + strings::info(a); +} + +pub fn crash(a: String, b: i32) { + strings::crash(a, b); +} \ No newline at end of file diff --git a/src/internal/strings.rs b/src/internal/strings.rs index 8b13789..e7ad34d 100755 --- a/src/internal/strings.rs +++ b/src/internal/strings.rs @@ -1 +1,10 @@ +use std::process::exit; +pub fn info(a: String) { + println!("\x1b[2;22;30mμ\x1b[0m \x1b[1;37m{}\x1b[0m", a); +} + +pub fn crash(a: String, b: i32) { + println!("\x1b[2;22;31m❌:\x1b[0m \x1b[1;91m{}\x1b[0m", a); + exit(b); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2efb34a..f0257af 100755 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::env; use std::process::Command; use clap::{App, AppSettings, Arg, ArgSettings, SubCommand}; +use crate::internal::{crash, info}; use crate::workspace::read_cfg; @@ -83,7 +84,7 @@ fn main() { let config = workspace::read_cfg(); if config.mode == "workspace" { for r in config.repo { - println!("Cloning (workspace mode): {}", r); + info(format!("Cloning (workspace mode): {}", r)); Command::new("git") .args(&["clone", &r]) .spawn() @@ -93,7 +94,7 @@ fn main() { } } else if config.mode == "repository" { for r in config.repo { - println!("Cloning (repository mode): {}", r); + info(format!("Cloning (repository mode): {}", r)); Command::new("git") .args(&["clone", "--no-checkout", &r]) .spawn() @@ -101,7 +102,7 @@ fn main() { .wait() .unwrap(); - println!("Entering working directory: {}", r); + info(format!("Entering working directory: {}", r)); let dir = format!( "{}/{}", env::current_dir().unwrap().display(), @@ -109,7 +110,7 @@ fn main() { ); env::set_current_dir(dir).unwrap(); - println!("Resetting unstaged files: {}", r); + info(format!("Resetting unstaged files: {}", r)); Command::new("git") .arg("reset") .spawn() @@ -117,7 +118,7 @@ fn main() { .wait() .unwrap(); - println!("Checking out PKGBUILD: {}", r); + info(format!("Checking out PKGBUILD: {}", r)); Command::new("git") .args(&["checkout", "HEAD", "PKGBUILD"]) .spawn() @@ -126,14 +127,14 @@ fn main() { .unwrap(); } } else { - panic!("Invalid mode in mlc.toml"); + crash("Invalid mode in mlc.toml".to_string(), 1); } } if let true = matches.is_present("build") { let config = workspace::read_cfg(); if config.mode != "repository" { - panic!("Cannot build packages in workspace mode") + crash("Cannot build packages in workspace mode".to_string(), 2); } let packages: Vec = matches .subcommand() @@ -153,7 +154,7 @@ fn main() { for pkg in packages { if !repos.contains(&pkg) { - panic!("Package {} not found in repos in mlc.toml", pkg); + crash(format!("Package {} not found in repos in mlc.toml", pkg), 3); } else { repository::build(pkg); } @@ -163,7 +164,7 @@ fn main() { if let true = matches.is_present("pull") { let config = workspace::read_cfg(); for r in config.repo { - println!("Entering working directory: {}", r); + info(format!("Entering working directory: {}", r)); let dir = format!( "{}/{}", env::current_dir().unwrap().display(), @@ -186,4 +187,4 @@ fn main() { } repository::generate(); } -} +} \ No newline at end of file diff --git a/src/repository/package.rs b/src/repository/package.rs index d83bbd5..f1779e3 100755 --- a/src/repository/package.rs +++ b/src/repository/package.rs @@ -1,6 +1,7 @@ use std::path::Path; use std::process::Command; use std::{env, fs}; +use crate::crash; pub fn build(pkg: String) { let dir = env::current_dir().unwrap(); @@ -8,7 +9,7 @@ pub fn build(pkg: String) { fs::create_dir_all("out").unwrap(); } if !Path::exists(pkg.as_ref()) { - panic!("Git directory for {} not found, aborting", pkg); + crash(format!("Git directory for {} not found, aborting", pkg), 4); } env::set_current_dir(pkg).unwrap(); @@ -29,4 +30,4 @@ pub fn build(pkg: String) { .unwrap(); env::set_current_dir(dir).unwrap(); -} +} \ No newline at end of file diff --git a/src/workspace/read.rs b/src/workspace/read.rs index 8a7f287..caf3524 100755 --- a/src/workspace/read.rs +++ b/src/workspace/read.rs @@ -1,15 +1,16 @@ use std::fs; use std::path::Path; +use crate::crash; use crate::internal::structs::Config; pub fn read_cfg() -> Config { if !Path::exists("mlc.toml".as_ref()) { - panic!("mlc.toml file not found") + crash("Config file not found (mlc.toml)".to_string(), 5) } let file = fs::read_to_string("mlc.toml").unwrap(); let config: Config = toml::from_str(&file).unwrap(); config -} +} \ No newline at end of file