Skip to content

Commit

Permalink
support base64 decode and encode cmdline args
Browse files Browse the repository at this point in the history
  • Loading branch information
neevek committed May 22, 2024
1 parent 1ed2840 commit 242d57e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions src/bin/omnip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate pretty_env_logger;

fn main() -> Result<()> {
let args = parse_args()?;
if print_args_as_base64(&args) {
if args.decode_base64 || print_args_as_base64(&args) {
return Ok(());
}

Expand Down Expand Up @@ -58,6 +58,12 @@ fn parse_args() -> Result<OmnipArgs> {
.decode(base64_args)
.context("invalid base64")?,
)?;
if args.decode_base64 {
println!("{space_sep_args}");
// simply print the args and quit
return Ok(args);
}

let parts: Vec<String> = space_sep_args
.split_whitespace()
.map(String::from)
Expand All @@ -76,10 +82,10 @@ fn parse_args() -> Result<OmnipArgs> {
}

fn print_args_as_base64(args: &OmnipArgs) -> bool {
if args.print_base64 {
if args.encode_base64 {
let space_sep_args = env::args_os()
.skip(1)
.filter(|arg| arg != "-P" && arg != "--print-base64")
.filter(|arg| arg != "-E" && arg != "--encode-base64")
.map(|arg| {
arg.into_string()
.unwrap_or_else(|os_str| os_str.to_string_lossy().into_owned())
Expand Down Expand Up @@ -179,6 +185,10 @@ struct OmnipArgs {

/// Print the args as base64 string to be used in opp:// address, will be ignored if passing in
/// as an opp:// address, which can combine all args as a single base64 string
#[arg(short = 'P', long, action)]
print_base64: bool,
#[arg(short = 'E', long, action)]
encode_base64: bool,

/// Decode and print the base64 encoded opp:// address
#[arg(short = 'D', long, action)]
decode_base64: bool,
}

0 comments on commit 242d57e

Please sign in to comment.