@@ -9,7 +9,7 @@ use crate::{
9
9
} ;
10
10
11
11
#[ derive( Parser ) ]
12
- #[ command( author, version = env! ( "COTP_VERSION" ) , about, long_about = None ) ]
12
+ #[ command( author, version = env ! ( "COTP_VERSION" ) , about, long_about = None ) ]
13
13
pub struct CotpArgs {
14
14
#[ command( subcommand) ]
15
15
command : Option < CotpSubcommands > ,
@@ -24,6 +24,8 @@ enum CotpSubcommands {
24
24
Add ( AddArgs ) ,
25
25
/// Edit an existing OTP Code
26
26
Edit ( EditArgs ) ,
27
+ /// List codes
28
+ List ( ListArgs ) ,
27
29
/// Import codes from other apps
28
30
Import ( ImportArgs ) ,
29
31
/// Export cotp database
@@ -122,6 +124,13 @@ pub struct EditArgs {
122
124
pub change_secret : bool ,
123
125
}
124
126
127
+ #[ derive( Args ) ]
128
+ pub struct ListArgs {
129
+ /// List output format
130
+ #[ command( flatten) ]
131
+ pub format : Option < ExportFormat > ,
132
+ }
133
+
125
134
#[ derive( Args ) ]
126
135
pub struct ImportArgs {
127
136
#[ command( flatten) ]
@@ -132,18 +141,40 @@ pub struct ImportArgs {
132
141
pub path : PathBuf ,
133
142
}
134
143
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
+
135
166
#[ derive( Args ) ]
136
167
pub struct ExtractArgs {
137
168
/// Code Index
138
- #[ arg( short, long, required_unless_present_any= [ "issuer" , "label" ] ) ]
169
+ #[ arg( short, long, required_unless_present_any = [ "issuer" , "label" ] ) ]
139
170
pub index : Option < usize > ,
140
171
141
172
/// Code issuer
142
- #[ arg( short = 's' , long, required_unless_present_any= [ "index" , "label" ] ) ]
173
+ #[ arg( short = 's' , long, required_unless_present_any = [ "index" , "label" ] ) ]
143
174
pub issuer : Option < String > ,
144
175
145
176
/// Code label
146
- #[ arg( short, long, required_unless_present_any= [ "index" , "issuer" ] ) ]
177
+ #[ arg( short, long, required_unless_present_any = [ "index" , "issuer" ] ) ]
147
178
pub label : Option < String > ,
148
179
149
180
/// Copy the code to the clipboard
@@ -245,6 +276,7 @@ pub fn args_parser(matches: CotpArgs, read_result: OTPDatabase) -> color_eyre::R
245
276
match matches. command {
246
277
Some ( CotpSubcommands :: Add ( args) ) => argument_functions:: add ( args, read_result) ,
247
278
Some ( CotpSubcommands :: Edit ( args) ) => argument_functions:: edit ( args, read_result) ,
279
+ Some ( CotpSubcommands :: List ( args) ) => argument_functions:: list ( args, read_result) ,
248
280
Some ( CotpSubcommands :: Import ( args) ) => argument_functions:: import ( args, read_result) ,
249
281
Some ( CotpSubcommands :: Export ( args) ) => argument_functions:: export ( args, read_result) ,
250
282
Some ( CotpSubcommands :: Extract ( args) ) => argument_functions:: extract ( args, read_result) ,
0 commit comments