diff --git a/Cargo.lock b/Cargo.lock index 78158bd..47b14a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,222 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anstream" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "clap" +version = "4.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "no" -version = "0.1.0" +version = "0.2.0" +dependencies = [ + "clap", +] + +[[package]] +name = "proc-macro2" +version = "1.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml index 6d3fa0a..886f155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,17 @@ [package] name = "no" -version = "0.1.0" +version = "0.2.0" edition = "2021" +license = "GPL-3.0" +description = "Output a string repeatedly until killed." +homepage = "https://github.com/metamethods/no" +documentation = "https://github.com/metamethods/no/blob/master/README.md" +repository = "https://github.com/metamethods/no" +readme = "README.md" +keywords = ["unix", "no"] +authors = ["metamethods "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4.12", features = ["derive"] } diff --git a/README.md b/README.md index c7b7e5c..969abf5 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,14 @@ Repeatedly output a line with all specified STRING(s), or 'n'. ## Usage ```bash -no [STRING] +no [STRINGS] ``` -```bash -no OPTIONS -``` \ No newline at end of file + +## Building +### Prerequisites +* [Rustup](https://rustup.rs/) + +### Instructions +1. Clone this repository via `git clone https://github.com/metamethods/no` +2. Build with `cargo` using `cargo build --release` +3. The binary will be located at `target/release/no` \ No newline at end of file diff --git a/install-manpage.sh b/install-manpage.sh deleted file mode 100755 index 0be8e19..0000000 --- a/install-manpage.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Pretty much only works on linux, not mac :whyyyy: - -sudo cp ./no.1 /usr/share/man/man1/ -sudo mandb \ No newline at end of file diff --git a/no.1 b/no.1 deleted file mode 100644 index 1b36a6b..0000000 --- a/no.1 +++ /dev/null @@ -1,45 +0,0 @@ -.\" Man page for no. -.\" Contact tabledmetamethods@gmail.com to correct errors or typos. - -.TH man 1 "Jan 1, 2024" "GNU ballutils 1.0" "General Commands Manual" - -.SH NAME -no \- output a string repeatedly until killed - -.SH SYNOPSIS -no [STRING] - -no OPTION - -.SH DESCRIPTION -Repeatedly output a line with all specified STRING(s), or 'n'. - -.SH OPTIONS -.TP -.B \-\-help -display this help and exit -.TP -.B \-\-version -output version information and exit - -.SH AUTHOR -Written by metamethods. - -.SH REPORTING BUGS -GNU ballutils online help: - -Report any translation bugs to (But why would you do that) - -.SH COPYRIGHT -Copyright © 2024 Free Software Foundation, Inc. License GPLv3+: GNU - -GPL version 3 or later . - -This is free software: you are free to change and redistribute it. - -There is NO WARRANTY, to the extent permitted by law. - -.SH SEE ALSO -Full documentation at: - -or available locally via: info '(ballutils) no invocation' \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6dd3ed8..7698930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,66 +1,19 @@ -// This is the most shittiest code but it works lmao +use clap::Parser; -fn has_flag(flags: Vec, arguments: &Vec) -> bool { - return flags.iter().any(|flag| arguments.contains(flag)); -} - -fn get_flags(arguments: &Vec) -> Vec { - let mut flags: Vec = Vec::new(); - for argument in arguments { - if argument.starts_with("-") { - flags.push(argument.clone()); - } - } - return flags; +/// Repeatedly output a line with all specified STRING(s), or 'n'. +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + strings: Option>, } fn main() { - let arguments: Vec = std::env::args().collect(); - - let help_flag: bool = has_flag(vec!["--help".to_string()], &arguments); - let version_flag: bool = has_flag(vec!["--version".to_string()], &arguments); - - let flags = get_flags(&arguments); - let valid_flags = vec!["--help".to_string(), "--version".to_string()]; - - let expletive = arguments.get(1) - .unwrap_or(&"n".to_string()).clone(); - - for flag in flags { - if !valid_flags.contains(&flag) { - println!("no: invalid option -- '{}'", flag); - println!("Try 'no --help' for more information."); - - std::process::exit(1); - } - } - - if help_flag { - println!("Usage: no [STRING]..."); - println!("or: no OPTION"); - println!("Repeatedly output a line with all specified STRING(s), or 'n'.\n"); - println!(" --help display this help and exit"); - println!(" --version output version information and exit\n"); - println!("GNU ballutils online help: "); - println!("Report any translation bugs to "); - println!("Full documentation "); - println!("or available locally via: info '(ballutils) no invocation'"); - - std::process::exit(0); - } - - if version_flag { - println!("no (GNU ballutils) 1.0"); - println!("Copyright (C) 2024 Free Software Foundation, Inc."); - println!("License GPLv3+: GNU GPL version 3 or later ."); - println!("This is free software: you are free to change and redistribute it."); - println!("There is NO WARRANTY, to the extent permitted by law.\n"); - println!("Written by metamethods."); - - std::process::exit(0); - } - loop { - println!("{expletive}"); + println!( + "{}", + Args::parse().strings + .unwrap_or(vec!["n".to_string()]) + .join(" ") + ); } -} +} \ No newline at end of file