Skip to content

Commit 8814a5e

Browse files
committed
Revert "fix: 🚀 remove otp-uri argument as now otp uris can be imported (#397)"
This reverts commit 50e647e, reversing changes made to cb58b67.
1 parent 81ffa60 commit 8814a5e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/args.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ enum CotpSubcommands {
3636

3737
#[derive(Args)]
3838
pub struct AddArgs {
39+
/// Add OTP code via an OTP URI
40+
#[arg(short = 'u', long = "otpuri", required_unless_present = "label")]
41+
pub otp_uri: bool,
42+
3943
/// Specify the OTP code type
4044
#[arg(short = 't', long = "type", default_value = "totp")]
4145
pub otp_type: OTPType,
@@ -45,7 +49,7 @@ pub struct AddArgs {
4549
pub issuer: String,
4650

4751
/// Code label
48-
#[arg(short, long, required = true)]
52+
#[arg(short, long, required_unless_present = "otp_uri")]
4953
pub label: Option<String>,
5054

5155
/// OTP Algorithm

src/argument_functions.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::importers::authy_remote_debug::AuthyExportedList;
77
use crate::importers::converted::ConvertedJsonList;
88
use crate::importers::freeotp_plus::FreeOTPPlusJson;
99
use crate::importers::importer::import_from_path;
10+
use crate::otp::from_otp_uri::FromOtpUri;
1011
use crate::otp::otp_element::{OTPDatabase, OTPElement};
1112
use crate::{clipboard, utils};
1213
use color_eyre::eyre::{eyre, ErrReport};
@@ -48,8 +49,14 @@ pub fn import(matches: ImportArgs, mut database: OTPDatabase) -> color_eyre::Res
4849
}
4950

5051
pub fn add(matches: AddArgs, mut database: OTPDatabase) -> color_eyre::Result<OTPDatabase> {
51-
let otp_element = get_from_args(matches)?;
52-
52+
let otp_element = if matches.otp_uri {
53+
let mut otp_uri = rpassword::prompt_password("Insert the otp uri: ").unwrap();
54+
let result = OTPElement::from_otp_uri(otp_uri.as_str());
55+
otp_uri.zeroize();
56+
result?
57+
} else {
58+
get_from_args(matches)?
59+
};
5360
if !otp_element.valid_secret() {
5461
return Err(ErrReport::msg("Invalid secret."));
5562
}

0 commit comments

Comments
 (0)