forked from mike-engel/jwt-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
45 lines (38 loc) · 1.24 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use clap::Parser;
use cli_config::{App, Commands, EncodeArgs};
use std::process::exit;
use translators::decode::{decode_token, print_decoded_token};
use translators::encode::{encode_token, print_encoded_token};
pub mod cli_config;
pub mod translators;
pub mod utils;
fn warn_unsupported(arguments: &EncodeArgs) {
if arguments.typ.is_some() {
println!("Sorry, `typ` isn't supported quite yet!");
};
}
fn main() {
let app = App::parse();
// let matches = config_options().get_matches();
match &app.command {
Commands::Encode(arguments) => {
warn_unsupported(arguments);
let token = encode_token(arguments);
let output_path = &arguments.output_path;
exit(match print_encoded_token(token, output_path) {
Ok(_) => 0,
_ => 1,
});
}
Commands::Decode(arguments) => {
let (validated_token, token_data, format) = decode_token(arguments);
let output_path = &arguments.output_path;
exit(
match print_decoded_token(validated_token, token_data, format, output_path) {
Ok(_) => 0,
_ => 1,
},
);
}
};
}