generated from PlexSheep/rs-base
feat/other-formats #7
|
@ -14,7 +14,7 @@ keywords = ["cli"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.83"
|
anyhow = "1.0.83"
|
||||||
base64 = "0.22.1"
|
|
||||||
clap = { version = "4.5.4", features = ["derive"] }
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
clap-num = "1.1.1"
|
clap-num = "1.1.1"
|
||||||
|
fast32 = "1.0.2"
|
||||||
PlexSheep marked this conversation as resolved
|
|||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use base64::prelude::*;
|
use fast32;
|
||||||
|
|
||||||
pub type Num = u128;
|
pub type Num = u128;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ pub enum Format {
|
||||||
Bin,
|
Bin,
|
||||||
Octal,
|
Octal,
|
||||||
Base64,
|
Base64,
|
||||||
|
Base32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format {
|
impl Format {
|
||||||
|
@ -25,6 +26,8 @@ impl Format {
|
||||||
Format::Octal => "0o",
|
Format::Octal => "0o",
|
||||||
// perl and a few other programs seem to use this too
|
// perl and a few other programs seem to use this too
|
||||||
Format::Base64 => "0s",
|
Format::Base64 => "0s",
|
||||||
|
// no idea, I made this up
|
||||||
|
Format::Base32 => "032s",
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
@ -46,7 +49,8 @@ impl Format {
|
||||||
Format::Dec => {
|
Format::Dec => {
|
||||||
buf += &format!("{num}");
|
buf += &format!("{num}");
|
||||||
}
|
}
|
||||||
Format::Base64 => buf += &BASE64_STANDARD.encode(u128_to_u8_slice(num)),
|
Format::Base64 => buf += &fast32::base64::RFC4648.encode(&u128_to_u8_slice(num)),
|
||||||
|
Format::Base32 => buf += &fast32::base32::RFC4648.encode(&u128_to_u8_slice(num)),
|
||||||
}
|
}
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use format::*;
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
#[clap(group(
|
#[clap(group(
|
||||||
ArgGroup::new("format")
|
ArgGroup::new("format")
|
||||||
.args(&["hex", "bin", "oct", "dec", "base64"]),
|
.args(&["hex", "bin", "oct", "dec", "base64", "base32"]),
|
||||||
))]
|
))]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
@ -34,6 +34,9 @@ struct Cli {
|
||||||
#[arg(short = 's', long)]
|
#[arg(short = 's', long)]
|
||||||
/// format to base64
|
/// format to base64
|
||||||
base64: bool,
|
base64: bool,
|
||||||
|
#[arg(short = 'z', long)]
|
||||||
|
/// format to base32
|
||||||
|
base32: bool,
|
||||||
#[clap(value_parser=maybe_hex::<Num>, required=true)]
|
#[clap(value_parser=maybe_hex::<Num>, required=true)]
|
||||||
/// at least one number that should be formatted
|
/// at least one number that should be formatted
|
||||||
///
|
///
|
||||||
|
@ -51,6 +54,8 @@ impl Cli {
|
||||||
Format::Dec
|
Format::Dec
|
||||||
} else if self.base64 {
|
} else if self.base64 {
|
||||||
Format::Base64
|
Format::Base64
|
||||||
|
} else if self.base32 {
|
||||||
|
Format::Base32
|
||||||
} else if self.hex {
|
} else if self.hex {
|
||||||
Format::Hex
|
Format::Hex
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in New Issue
seems okay