-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version, add building instructions, and use clap for parsing a…
…rguments
- Loading branch information
1 parent
674f813
commit 33fe597
Showing
6 changed files
with
250 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.4.12", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,19 @@ | ||
// This is the most shittiest code but it works lmao | ||
use clap::Parser; | ||
|
||
fn has_flag(flags: Vec<String>, arguments: &Vec<String>) -> bool { | ||
return flags.iter().any(|flag| arguments.contains(flag)); | ||
} | ||
|
||
fn get_flags(arguments: &Vec<String>) -> Vec<String> { | ||
let mut flags: Vec<String> = 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<Vec<String>>, | ||
} | ||
|
||
fn main() { | ||
let arguments: Vec<String> = 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: <doesn't exist :troll:>"); | ||
println!("Report any translation bugs to <nope>"); | ||
println!("Full documentation <no documents to ever be made>"); | ||
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 <https://gnu.org/licenses/gpl.html>."); | ||
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(" ") | ||
); | ||
} | ||
} | ||
} |