upgrade to clap v3, convert global level arguments
This commit is contained in:
parent
a19f379314
commit
abe808b7bf
3 changed files with 151 additions and 54 deletions
96
Cargo.lock
generated
96
Cargo.lock
generated
|
@ -29,15 +29,6 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.57"
|
||||
|
@ -192,17 +183,41 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.34.0"
|
||||
version = "3.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
|
||||
checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"lazy_static 1.4.0",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -578,6 +593,12 @@ version = "0.11.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
|
@ -938,6 +959,12 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
|
@ -1097,6 +1124,30 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.19"
|
||||
|
@ -1860,9 +1911,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
|
@ -1957,12 +2008,9 @@ checksum = "442f2674e6bd8489052b958e0eaebd89c26eefa3be9dc359d1e2ecccdc510f45"
|
|||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||
|
||||
[[package]]
|
||||
name = "thin-slice"
|
||||
|
@ -2232,12 +2280,6 @@ dependencies = [
|
|||
"getrandom 0.2.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
|
|
@ -7,7 +7,7 @@ members = [
|
|||
[package]
|
||||
name = "steamguard-cli"
|
||||
version = "0.4.5"
|
||||
authors = ["Carson McManus <carson.mcmanus1@gmail.com>"]
|
||||
authors = ["dyc3 (Carson McManus) <carson.mcmanus1@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "A command line utility to generate Steam 2FA codes and respond to confirmations."
|
||||
keywords = ["steam", "2fa", "steamguard", "authentication", "cli"]
|
||||
|
@ -33,7 +33,7 @@ serde_json = "1.0"
|
|||
rsa = "0.5.0"
|
||||
rand = "0.8.4"
|
||||
standback = "0.2.17" # required to fix a compilation error on a transient dependency
|
||||
clap = "2.33.3"
|
||||
clap = { version = "3.1.18", features = ["derive", "cargo"] }
|
||||
log = "0.4.14"
|
||||
stderrlog = "0.4"
|
||||
cookie = "0.14"
|
||||
|
|
105
src/main.rs
105
src/main.rs
|
@ -1,5 +1,5 @@
|
|||
extern crate rpassword;
|
||||
use clap::{crate_version, App, Arg, ArgMatches, Shell};
|
||||
use clap::{crate_version, App, Arg, ArgMatches, Parser};
|
||||
use log::*;
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
|
@ -29,7 +29,59 @@ mod encryption;
|
|||
mod errors;
|
||||
mod tui;
|
||||
|
||||
fn cli() -> App<'static, 'static> {
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[clap(short, long, help = "Steam username, case-sensitive.", long_help = "Select the account you want by steam username. Case-sensitive. By default, the first account in the manifest is selected.")]
|
||||
username: Option<String>,
|
||||
#[clap(short, long, help = "Select all accounts in the manifest.")]
|
||||
all: bool,
|
||||
/// The path to the maFiles directory.
|
||||
#[clap(short, long, default_value = "~/.config/steamguard-cli/maFiles", help = "Specify which folder your maFiles are in. This should be a path to a folder that contains manifest.json.")]
|
||||
mafiles_path: String,
|
||||
#[clap(short, long, help = "Specify your encryption passkey.")]
|
||||
passkey: Option<String>,
|
||||
#[clap(short, long, default_value_t=Verbosity::Info, help = "Set the log level.")]
|
||||
verbosity: Verbosity,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Verbosity {
|
||||
Error = 0,
|
||||
Warn = 1,
|
||||
Info = 2,
|
||||
Debug = 3,
|
||||
Trace = 4,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Verbosity {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("{}", match self {
|
||||
Verbosity::Error => "error",
|
||||
Verbosity::Warn => "warn",
|
||||
Verbosity::Info => "info",
|
||||
Verbosity::Debug => "debug",
|
||||
Verbosity::Trace => "trace",
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Verbosity {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"error" => Ok(Verbosity::Error),
|
||||
"warn" => Ok(Verbosity::Warn),
|
||||
"info" => Ok(Verbosity::Info),
|
||||
"debug" => Ok(Verbosity::Debug),
|
||||
"trace" => Ok(Verbosity::Trace),
|
||||
_ => Err(anyhow!("Invalid verbosity level: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cli() -> App<'static> {
|
||||
App::new("steamguard-cli")
|
||||
.version(crate_version!())
|
||||
.bin_name("steamguard")
|
||||
|
@ -38,7 +90,7 @@ fn cli() -> App<'static, 'static> {
|
|||
.arg(
|
||||
Arg::with_name("username")
|
||||
.long("username")
|
||||
.short("u")
|
||||
.short('u')
|
||||
.takes_value(true)
|
||||
.help("Select the account you want by steam username. Case-sensitive. By default, the first account in the manifest is selected.")
|
||||
.conflicts_with("all")
|
||||
|
@ -46,7 +98,7 @@ fn cli() -> App<'static, 'static> {
|
|||
.arg(
|
||||
Arg::with_name("all")
|
||||
.long("all")
|
||||
.short("a")
|
||||
.short('a')
|
||||
.takes_value(false)
|
||||
.help("Select all accounts in the manifest.")
|
||||
.conflicts_with("username")
|
||||
|
@ -54,40 +106,40 @@ fn cli() -> App<'static, 'static> {
|
|||
.arg(
|
||||
Arg::with_name("mafiles-path")
|
||||
.long("mafiles-path")
|
||||
.short("m")
|
||||
.short('m')
|
||||
.default_value("~/maFiles")
|
||||
.help("Specify which folder your maFiles are in. This should be a path to a folder that contains manifest.json.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("passkey")
|
||||
.long("passkey")
|
||||
.short("p")
|
||||
.short('p')
|
||||
.help("Specify your encryption passkey.")
|
||||
.takes_value(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("verbosity")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.help("Log what is going on verbosely.")
|
||||
.takes_value(false)
|
||||
.multiple(true)
|
||||
)
|
||||
.subcommand(
|
||||
App::new("completion")
|
||||
.about("Generate shell completions")
|
||||
.arg(
|
||||
Arg::with_name("shell")
|
||||
.long("shell")
|
||||
.takes_value(true)
|
||||
.possible_values(&Shell::variants())
|
||||
)
|
||||
)
|
||||
// .subcommand(
|
||||
// App::new("completion")
|
||||
// .about("Generate shell completions")
|
||||
// .arg(
|
||||
// Arg::with_name("shell")
|
||||
// .long("shell")
|
||||
// .takes_value(true)
|
||||
// .possible_values(&Shell::variants())
|
||||
// )
|
||||
// )
|
||||
.subcommand(
|
||||
App::new("trade")
|
||||
.about("Interactive interface for trade confirmations")
|
||||
.arg(
|
||||
Arg::with_name("accept-all")
|
||||
.short("a")
|
||||
.short('a')
|
||||
.long("accept-all")
|
||||
.takes_value(false)
|
||||
.help("Accept all open trade confirmations. Does not open interactive interface.")
|
||||
|
@ -144,11 +196,14 @@ fn main() {
|
|||
}
|
||||
|
||||
fn run() -> anyhow::Result<()> {
|
||||
let new_args = Args::parse();
|
||||
println!("{:?}", new_args);
|
||||
return Ok(());
|
||||
|
||||
let matches = cli().get_matches();
|
||||
|
||||
let verbosity = matches.occurrences_of("verbosity") as usize + 2;
|
||||
stderrlog::new()
|
||||
.verbosity(verbosity)
|
||||
.verbosity(new_args.verbosity as usize)
|
||||
.module(module_path!())
|
||||
.module("steamguard")
|
||||
.init()
|
||||
|
@ -161,11 +216,11 @@ fn run() -> anyhow::Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
if let Some(completion_matches) = matches.subcommand_matches("completion") {
|
||||
cli().gen_completions_to(
|
||||
"steamguard",
|
||||
Shell::from_str(completion_matches.value_of("shell").unwrap()).unwrap(),
|
||||
&mut std::io::stdout(),
|
||||
);
|
||||
// cli().gen_completions_to(
|
||||
// "steamguard",
|
||||
// Shell::from_str(completion_matches.value_of("shell").unwrap()).unwrap(),
|
||||
// &mut std::io::stdout(),
|
||||
// );
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue