Skip to content

Commit 35673f2

Browse files
committed
feat: add new List subcommand
1 parent c877894 commit 35673f2

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/args.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010

1111
#[derive(Parser)]
12-
#[command(author, version = env!("COTP_VERSION"), about, long_about = None)]
12+
#[command(author, version = env ! ("COTP_VERSION"), about, long_about = None)]
1313
pub struct CotpArgs {
1414
#[command(subcommand)]
1515
command: Option<CotpSubcommands>,
@@ -24,6 +24,8 @@ enum CotpSubcommands {
2424
Add(AddArgs),
2525
/// Edit an existing OTP Code
2626
Edit(EditArgs),
27+
/// List codes
28+
List(ListArgs),
2729
/// Import codes from other apps
2830
Import(ImportArgs),
2931
/// Export cotp database
@@ -122,6 +124,13 @@ pub struct EditArgs {
122124
pub change_secret: bool,
123125
}
124126

127+
#[derive(Args)]
128+
pub struct ListArgs {
129+
/// List output format
130+
#[command(flatten)]
131+
pub format: Option<ExportFormat>,
132+
}
133+
125134
#[derive(Args)]
126135
pub struct ImportArgs {
127136
#[command(flatten)]
@@ -132,18 +141,40 @@ pub struct ImportArgs {
132141
pub path: PathBuf,
133142
}
134143

144+
/// Defines the output formats of the list subcommand
145+
#[derive(Args)]
146+
#[group(required = false, multiple = false)]
147+
pub struct ListFormat {
148+
/// List OTP codes in plain format
149+
#[arg(short, long)]
150+
pub plain: bool,
151+
152+
/// List OTP codes in JSON format
153+
#[arg(short = 'e', long)]
154+
pub json: bool,
155+
}
156+
157+
impl Default for ListFormat {
158+
fn default() -> Self {
159+
Self {
160+
plain: true,
161+
json: false,
162+
}
163+
}
164+
}
165+
135166
#[derive(Args)]
136167
pub struct ExtractArgs {
137168
/// Code Index
138-
#[arg(short, long, required_unless_present_any=["issuer", "label"])]
169+
#[arg(short, long, required_unless_present_any = ["issuer", "label"])]
139170
pub index: Option<usize>,
140171

141172
/// Code issuer
142-
#[arg(short = 's', long, required_unless_present_any=["index","label"])]
173+
#[arg(short = 's', long, required_unless_present_any = ["index", "label"])]
143174
pub issuer: Option<String>,
144175

145176
/// Code label
146-
#[arg(short, long, required_unless_present_any=["index", "issuer"])]
177+
#[arg(short, long, required_unless_present_any = ["index", "issuer"])]
147178
pub label: Option<String>,
148179

149180
/// Copy the code to the clipboard
@@ -245,6 +276,7 @@ pub fn args_parser(matches: CotpArgs, read_result: OTPDatabase) -> color_eyre::R
245276
match matches.command {
246277
Some(CotpSubcommands::Add(args)) => argument_functions::add(args, read_result),
247278
Some(CotpSubcommands::Edit(args)) => argument_functions::edit(args, read_result),
279+
Some(CotpSubcommands::List(args)) => argument_functions::list(args, read_result),
248280
Some(CotpSubcommands::Import(args)) => argument_functions::import(args, read_result),
249281
Some(CotpSubcommands::Export(args)) => argument_functions::export(args, read_result),
250282
Some(CotpSubcommands::Extract(args)) => argument_functions::extract(args, read_result),

src/argument_functions.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::args::{AddArgs, EditArgs, ExportArgs, ExtractArgs, ImportArgs};
1+
use crate::args::{AddArgs, EditArgs, ExportArgs, ExtractArgs, ImportArgs, ListArgs};
22
use crate::exporters::do_export;
33
use crate::exporters::otp_uri::OtpUriList;
44
use crate::importers::aegis::AegisJson;
@@ -133,6 +133,10 @@ pub fn edit(matches: EditArgs, mut database: OTPDatabase) -> color_eyre::Result<
133133
}
134134
}
135135

136+
pub fn list(matches: ListArgs, mut database: OTPDatabase) -> color_eyre::Result<OTPDatabase> {
137+
todo!()
138+
}
139+
136140
pub fn export(matches: ExportArgs, database: OTPDatabase) -> color_eyre::Result<OTPDatabase> {
137141
let export_format = matches.format.unwrap_or_default();
138142
let exported_path = if matches.path.is_dir() {

0 commit comments

Comments
 (0)