diff --git a/Cargo.lock b/Cargo.lock index 9508192..3ba040a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,9 +123,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "proc-macro2" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe8df9bd9fe9d1742a9e17f8129712801b428f6d4c6059d79bacea58f0b0142d" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] diff --git a/Cargo.toml b/Cargo.toml index 85cc774..03e0e16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,13 +5,25 @@ version = "0.1.0" edition = "2021" authors = ["Stridsvagn69420 (https://github.com/Stridsvagn69420)"] readme = "README.md" +build = "build.rs" license = "MIT" repository = "https://github.com/Stridsvagn69420/rmdup" documentation = "https://github.com/Stridsvagn69420/rmdup" categories = ["command-line-utilities", "filesystem"] keywords = ["coreutils", "command-line", "duplicate"] - +exclude = [ + ".github/", + ".vscode/", + ".git/", + "target/" +] [dependencies] blake3 = "1.4" -kagero = { version = "0.4", default-features = false, features = ["printer"] } \ No newline at end of file +kagero = { version = "0.4", default-features = false, features = ["printer"] } + +[profile.release] +lto = true +strip = true +debug = false +opt-level = 3 \ No newline at end of file diff --git a/README.md b/README.md index 2204412..f2760ba 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # rmdup -Simple tool for removing duplicate files \ No newline at end of file +Simple tool for removing duplicate files + +# Usage +```rmdup ``` +You just pass a file and it will scan the Current Working Directory for files that have the same [BLAKE3](https://github.com/BLAKE3-team/BLAKE3) hash. + +This tool is likely to get even more functionality in the future. If you'd like to have a feature added, just open a new Issue. + +# Installation +## Cargo +```cargo install rmdup``` + +## GitHub +There are also precompiled binaries on GitHub. Just go to the [Release](https://github.com/Stridsvagn69420/rmdup/releases) Page and download the standalone binary for your platform. \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..569fd35 --- /dev/null +++ b/build.rs @@ -0,0 +1,44 @@ +use std::process::Command; +use std::path::Path; +use std::io; +use std::env; + +fn main() { + // ----- Target Triple ----- + println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); + + // ----- Rust Version ----- + println!("cargo:rustc-env=CARGO_VERSION={}", version("cargo")); + println!("cargo:rustc-env=RUSTC_VERSION={}", version("rustc")); + + // ----- Git Data ----- + if Path::new(".git").exists() { + // Get the current branch name + match git(&["symbolic-ref", "--short", "HEAD"]) { + Ok(branch) => println!("cargo:rustc-env=GIT_BRANCH_TAG={}", branch), + // Try to get tag if you're not on a branch + Err(_) => { + if let Ok(tag) = git(&["describe", "--tags", "--exact-match"]) { + println!("cargo:rustc-env=GIT_BRANCH_TAG={}", tag) + } + } + } + // Get Latest Commit Hash + if let Ok(hash) = git(&["rev-parse", "--short", "HEAD"]) { + println!("cargo:rustc-env=GIT_HASH={}", hash); + }; + } +} + +fn git(args: &[&str]) -> io::Result { + let output = Command::new("git") + .args(args) + .output()?; + Ok(String::from_utf8(output.stdout).unwrap()) +} + +fn version(name: &str) -> String { + let output = Command::new(name).arg("--version").output().unwrap(); + let raw = String::from_utf8(output.stdout).unwrap(); + raw.replace(&format!("{} ", name), "") +} \ No newline at end of file diff --git a/src/help.rs b/src/help.rs index 54c5ac3..bad06c1 100644 --- a/src/help.rs +++ b/src/help.rs @@ -1,15 +1,62 @@ use kagero::printer::{Colors, Printer}; +use std::env::consts::{ARCH, OS}; + +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const NAME: &str = env!("CARGO_PKG_NAME"); +const REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY"); +const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); +const TARGET: &str = env!("TARGET"); +const CARGO_VERSION: &str = env!("CARGO_VERSION"); +const RUSTC_VERSION: &str = env!("RUSTC_VERSION"); +static GIT_BRANCH_TAG: Option<&str> = option_env!("GIT_BRANCH_TAG"); +static GIT_HASH: Option<&str> = option_env!("GIT_HASH"); /// Help Message /// /// Displays a help message for using this tool. pub(crate) fn help_message(p: &mut Printer) { - p.writeln("Help Message still WIP"); + // Usage + p.print("USAGE: ", Colors::RedBright).print(NAME, Colors::Red).println(" ", Colors::Red) + .writeln("") + + // Args + .println("ARGS:", Colors::MagentaBright) + .print("FILE: ", Colors::Magenta).writeln("Path to the file whose duplicates are to be deleted") + .writeln("") + + // Flags + .println("FLAGS:", Colors::CyanBright) + .print("-V, --version: ", Colors::Cyan).writeln("Prints metadata of this tool") + .print("-h, --help:", Colors::Cyan).writeln("Prints this help message"); + } /// Version Message /// -/// Prints metadata like authors and version of the program. +/// Prints metadata of the program. pub(crate) fn version(p: &mut Printer) { - p.writeln("Version Message still WIP"); + // Name and Description + p.print(NAME, Colors::RedBright) + .print(" - ", Colors::RedBright) + .println(DESCRIPTION, Colors::RedBright) + + // Version + .print("Version: ", Colors::Magenta) + .write("v").write(VERSION).write("@").write(OS).write("-").writeln(ARCH); // format!("v{VERSION}@{OS}-{ARCH}") + + // Repository and Git + p.print("Repository: ", Colors::Magenta).writeln(REPOSITORY) + .print("Build: ", Colors::Magenta); + if GIT_BRANCH_TAG.is_some() && GIT_HASH.is_some() { + p.write(GIT_HASH.unwrap()) + .write("@") + .writeln(GIT_BRANCH_TAG.unwrap()); + } else { + p.write(VERSION).writeln("@crates.io"); + } + + // Rust + p.print("Target: ", Colors::Blue).writeln(TARGET) + .print("Rust: ", Colors::Blue).writeln(RUSTC_VERSION) + .print("Cargo: ", Colors::Blue).writeln(CARGO_VERSION); } \ No newline at end of file