feat: add the base32 command
This commit is contained in:
parent
72f3d3dc46
commit
1bd25373cd
6 changed files with 44 additions and 0 deletions
39
coreutils/src/commands/base32.rs
Normal file
39
coreutils/src/commands/base32.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
use boxutils::args::ArgParser;
|
||||||
|
use boxutils::commands::Command;
|
||||||
|
use boxutils::encoding::base32;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
// TODO: Add the -w flag
|
||||||
|
// we dont have a way to do text
|
||||||
|
// warping in boxutils yet haha
|
||||||
|
|
||||||
|
pub struct Base32;
|
||||||
|
|
||||||
|
impl Command for Base32 {
|
||||||
|
fn execute(&self) {
|
||||||
|
let args = ArgParser::builder()
|
||||||
|
.add_flag("-d") // decode flag
|
||||||
|
.parse_args("base32");
|
||||||
|
|
||||||
|
let decode = args.get_flag("-d");
|
||||||
|
|
||||||
|
// FIXME: This is jank!
|
||||||
|
let mut file: Box<dyn Read> = match &args.get_normal_args()[..] {
|
||||||
|
[] => Box::new(std::io::stdin()),
|
||||||
|
[file] => Box::new(OpenOptions::new().read(true).open(file).unwrap()),
|
||||||
|
_ => panic!("base32: multiple files provided"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut buffer = String::new();
|
||||||
|
while boxutils::input::repl_with_file(&mut file, &mut buffer) {
|
||||||
|
let data = if decode {
|
||||||
|
base32::decode(buffer.clone())
|
||||||
|
} else {
|
||||||
|
base32::encode(buffer.clone())
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{}", data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,3 +21,4 @@ command!(whoami::WhoAmI);
|
||||||
command!(hostname::Hostname);
|
command!(hostname::Hostname);
|
||||||
command!(tee::Tee);
|
command!(tee::Tee);
|
||||||
command!(base64::Base64);
|
command!(base64::Base64);
|
||||||
|
command!(base32::Base32);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ pub fn get_registry() -> CommandRegistry {
|
||||||
"hostname" => coreutils::commands::Hostname,
|
"hostname" => coreutils::commands::Hostname,
|
||||||
"tee" => coreutils::commands::Tee,
|
"tee" => coreutils::commands::Tee,
|
||||||
"base64" => coreutils::commands::Base64,
|
"base64" => coreutils::commands::Base64,
|
||||||
|
"base32" => coreutils::commands::Base32,
|
||||||
"box" => Boxcmd
|
"box" => Boxcmd
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ pub fn decode(to_decode: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#[allow(unused_imports)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ pub fn decode(to_decode: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#[allow(unused_imports)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ pub fn decode(to_decode: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#[allow(unused_imports)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue