From 86595a33659ffa6a0e781f4cdfd2821ddee85a35 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Mon, 16 Aug 2021 12:13:02 +0300 Subject: [PATCH] README, pre-added flag, and little fumofiles search improvements --- Cargo.lock | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- README.md | 24 ++++++++++-- src/main.rs | 48 ++++++++++++++++------- 4 files changed, 165 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3979d85..2cfae04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,114 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "fumosay" -version = "0.1.1" +version = "0.2.0" +dependencies = [ + "clap", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 0ccf15f..1c07a5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fumosay" -version = "0.1.1" +version = "0.2.0" edition = "2018" authors = ["Unbewohnte | Nikolay Kasyanov "] description = "Like cowsay, but with soft friends" @@ -10,3 +10,4 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = "~2.33.3" \ No newline at end of file diff --git a/README.md b/README.md index 401ed9c..864d36c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ ``` --- -## Compile +# Installation + +## Compile it yourself install Rust - [installation instructions](https://www.rust-lang.org/tools/install) @@ -30,9 +32,23 @@ compile for your OS && Architecture **or** -## Download a pre-compiled version +## Download a pre-compiled version (only amd64 Linux and Windows) - [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases) +## After compilation|downloading + +create a directory where the program will 'sit' +- `mkdir $HOME/fumosay` + +retrieve the executable and fumofiles and move them there +- `mv fumosay/target/release/fumo $HOME/fumosay/ && mv fumofiles $HOME/fumosay` + + +**Now you have fumosay installed !** + +The next possible step would probably be to add this directory to the $PATH environment variable. + + --- ## Use @@ -45,8 +61,8 @@ compile for your OS && Architecture ## TODO list - ❌ Add more fumos -- ❌ Make it available to use other fumos +- ❌ Make it possible to use other fumos - ❌ Improve message {box|bubble} -- ❌ Embed fumofiles or take care of ways of locating them +- somewhat ✅ Embed fumofiles or take care of ways of locating them - ❌ Create a {deb|rpm} package - ❌ Make an `install.sh` script diff --git a/src/main.rs b/src/main.rs index 216fb0f..591752b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use std::path::Path; use std::fs; use std::env; +use clap::{Arg, App}; /// Indicator of where the message should be in fumofile pub const MESSAGE_INDICATOR: &str = "!message"; @@ -19,25 +19,45 @@ fn process_message(fumofile_contents: &mut String, message: &str) -> String { fn main() { // get command line arguments - let args: Vec = env::args().collect(); + let matches = App::new("fumosay") + .version("0.2.0") + .author("Unbewohnte | Nikolay Kasyanov ") + .about("cowsay, but with soft friends") + .arg( + Arg::with_name("fumo") + .short("f") + .long("fumo") + .value_name("fumofile") + .help("choose another fumofumo to print") + .takes_value(true) + .required(false)) + .arg( + Arg::with_name("message") + .short("m") + .long("message") + .help("set a message to print") + .takes_value(true) + .required(true) + .index(1) + .multiple(true) + ).get_matches(); - // try to retrieve a message from args - if args.len() <= 1 { - // no message was provided - std::process::exit(1); - } - - let clarg_message: &String = &args[1..].join(" "); + // default path to the fumofile - // path to the fumofile - let fumofile_default_path: String = format!("./fumofiles/{}",FUMO_DEFAULT); - let fumofile_path: &Path = Path::new(&fumofile_default_path); + // grab path to exe + let executable_path = env::current_exe().expect("Could not get current exe`s path!"); + // remove the last bit (exe filename) + let executable_dir = executable_path.parent().expect("Could not get exe`s parent directory !"); + // local path to the default fumofile + let fumofile_default_path = std::path::Path::new("fumofiles").join(FUMO_DEFAULT); + // add them together + let fumofile_path = executable_dir.join(fumofile_default_path); // read fumofile - let mut fumofile_contents: String = fs::read_to_string(fumofile_path).unwrap(); + let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!"); // parse the file and get the resulting string - let message: String = process_message(&mut fumofile_contents, clarg_message); + let message: String = process_message(&mut fumofile_contents, matches.value_of("message").unwrap()); println!("{}", message); }