diff --git a/README.md b/README.md new file mode 100644 index 0000000..5973eb3 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +

+ + Logo + +

+

Malachite

+

+

+Discord

+ +

Malachite is a simple yet fast workspace and repo management tool, made for packagers of Arch Linux based distributions.

+ +## Basic usage + +| Action | Command | +|----------------------|--| +| Build a package | mlc build \ | +| Generate local repository | mlc repo-gen | +| Update local repos/PKGBUILDs | mlc pull/update | +| Create and/or open config file | mlc conf | + +## Exit codes overview + +| Exit Code (i32) | Reason | +|-----------------|----------------------------------------------------------| +| 1 | Running ame as UID 0 / root | +| 2 | Failed adding package to database | +| 3 | Failed initialising database | +| 4 | Error creating cache and/or database paths | +| 5 | Could not find one or more required package dependencies | +| 6 | User cancelled package installation | +| 7 | Pacman error when installing package | + +## How to build: + +Tested on latest Cargo (1.60.0-nightly) + +
+ +#### Debug/development builds + +- `cargo build` + +#### Optimised/release builds + +- `cargo build --release` + +#### Pkg-warner included + +- `cargo build (--release) --all --features=pkg-warner` + +
+
+ + \ No newline at end of file diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 4181caa..8ed88cb 100755 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -7,4 +7,4 @@ pub fn info(a: String) { 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 e7ad34d..3ce7f52 100755 --- a/src/internal/strings.rs +++ b/src/internal/strings.rs @@ -7,4 +7,4 @@ pub fn info(a: String) { 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 f0257af..8571d07 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ use std::env; +use std::path::Path; use std::process::Command; -use clap::{App, AppSettings, Arg, ArgSettings, SubCommand}; use crate::internal::{crash, info}; +use clap::{App, AppSettings, Arg, ArgSettings, SubCommand}; +use crate::repository::create_config; use crate::workspace::read_cfg; @@ -24,6 +26,7 @@ fn main() { .help("Sets the level of verbosity"), ) .arg( + // TODO implement --exclude Arg::with_name("exclude") .short("e") .long("exclude") @@ -32,6 +35,7 @@ fn main() { .help("Excludes packages from given operation"), ) .arg( + // TODO implement --all Arg::with_name("all") .long("all") .set(ArgSettings::Global) @@ -49,7 +53,7 @@ fn main() { ), ) .subcommand( - SubCommand::with_name("repo-gen").about("Generates repository from build packages"), + SubCommand::with_name("repo-gen").about("Generates repository from built packages"), ) .subcommand( SubCommand::with_name("prune") @@ -69,6 +73,9 @@ fn main() { "Pulls all git repositories from mlc.toml branching from current directory", ), ) + .subcommand( + SubCommand::with_name("config").about("Create and/or open local config file"), + ) .settings(&[ AppSettings::GlobalVersion, AppSettings::VersionlessSubcommands, @@ -163,6 +170,7 @@ fn main() { if let true = matches.is_present("pull") { let config = workspace::read_cfg(); + let cdir = env::current_dir().unwrap(); for r in config.repo { info(format!("Entering working directory: {}", r)); let dir = format!( @@ -177,6 +185,7 @@ fn main() { .unwrap() .wait() .unwrap(); + env::set_current_dir(&cdir).unwrap(); } } @@ -187,4 +196,17 @@ fn main() { } repository::generate(); } + + if let true = matches.is_present("config") { + if !Path::exists("mlc.toml".as_ref()) { + create_config(); + } + let editor = env::var("EDITOR").unwrap_or("nano".to_string()); + Command::new(editor) + .arg("mlc.toml") + .spawn() + .unwrap() + .wait() + .unwrap(); + } } \ No newline at end of file diff --git a/src/repository/config.rs b/src/repository/config.rs new file mode 100644 index 0000000..5b8d91a --- /dev/null +++ b/src/repository/config.rs @@ -0,0 +1,21 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::Path; +use crate::crash; + +const DEFAULT_CONFIG: &str = r#" +mode = "" # either "repository" or "workspace" +name = "" # only required when in repository mode, decides what to call the repository and relevant files +repo = [""] # an array of git repos to clone from +"#; + +pub fn create_config() { + if !env::current_dir().unwrap().read_dir().unwrap().next().is_none() { + crash("Directory is not empty, please only create a repository in an empty directory".to_string(), 6); + } + if !Path::exists("mlc.toml".as_ref()) { + let mut file = File::create("mlc.toml").unwrap(); + file.write_all(DEFAULT_CONFIG.as_ref()).unwrap(); + } +} \ No newline at end of file diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 240ab18..ecb4ec3 100755 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -1,5 +1,6 @@ mod package; mod repo; +mod config; pub fn build(pkg: String) { package::build(pkg); @@ -8,3 +9,7 @@ pub fn build(pkg: String) { pub fn generate() { repo::generate(); } + +pub fn create_config() { + config::create_config(); +} \ No newline at end of file diff --git a/src/repository/package.rs b/src/repository/package.rs index f1779e3..f3218fa 100755 --- a/src/repository/package.rs +++ b/src/repository/package.rs @@ -1,7 +1,7 @@ +use crate::crash; 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(); @@ -30,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 caf3524..25e75e1 100755 --- a/src/workspace/read.rs +++ b/src/workspace/read.rs @@ -1,6 +1,6 @@ +use crate::crash; use std::fs; use std::path::Path; -use crate::crash; use crate::internal::structs::Config; @@ -13,4 +13,4 @@ pub fn read_cfg() -> Config { let config: Config = toml::from_str(&file).unwrap(); config -} \ No newline at end of file +}