Skip to content

Commit

Permalink
Help and Version message
Browse files Browse the repository at this point in the history
  • Loading branch information
Stridsvagn69420 committed Jun 25, 2023
1 parent 7e498f2 commit 3aa0722
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
kagero = { version = "0.4", default-features = false, features = ["printer"] }

[profile.release]
lto = true
strip = true
debug = false
opt-level = 3
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# rmdup
Simple tool for removing duplicate files
Simple tool for removing duplicate files

# Usage
```rmdup <file.txt>```
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.
44 changes: 44 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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), "")
}
53 changes: 50 additions & 3 deletions src/help.rs
Original file line number Diff line number Diff line change
@@ -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(" <FILE>", 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);
}

0 comments on commit 3aa0722

Please sign in to comment.