Skip to content

Commit

Permalink
fix: issue with clap typeid casting by reverting to builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
lmammino committed Oct 26, 2023
1 parent 2e1e9d6 commit cb7185d
Show file tree
Hide file tree
Showing 3 changed files with 19 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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = [
repository = "https://github.com/lmammino/jwtinfo"
documentation = "https://github.com/lmammino/jwtinfo"
readme = "README.md"
version = "0.4.1"
version = "0.4.2"
authors = ["Luciano Mammino", "Stefano Abalsamo"]
edition = "2018"
license = "MIT"
Expand Down
21 changes: 17 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{arg, Command};
use clap::{Arg, ArgAction, Command};
use serde_json::to_string_pretty;
use std::io::{self, Read};
use std::process;
Expand All @@ -10,10 +10,23 @@ fn main() -> io::Result<()> {
let matches = Command::new("jwtinfo")
.version(env!("CARGO_PKG_VERSION"))
.about("Shows information about a JWT (Json Web Token)")
.arg(arg!(-h --header ... "Shows the token header rather than the body"))
.arg(arg!(<token> ... "the JWT as a string (use \"-\" to read from stdin)"))
.arg(arg!(-P --pretty ... "Pretty prints the JWT"))
.args([
Arg::new("header")
.short('H')
.long("header")
.action(ArgAction::SetTrue)
.help("Shows the token header rather than the body"),
Arg::new("pretty")
.short('P')
.long("pretty")
.action(ArgAction::SetTrue)
.help("Pretty prints the JWT header or body"),
Arg::new("token")
.index(1)
.help("the JWT as a string (use \"-\" to read from stdin)"),
])
.get_matches();

let should_pretty_print = matches.get_flag("pretty");

let mut token = matches.get_one::<String>("token").unwrap().clone();
Expand Down

0 comments on commit cb7185d

Please sign in to comment.