11use super :: zenodo;
2- use super :: Context ;
3- use clap:: { Parser , ValueEnum } ;
2+ use super :: { Context , Provider } ;
3+ use clap:: Parser ;
44use snafu:: { ResultExt , Snafu } ;
55use std:: env:: VarError ;
66use std:: path:: PathBuf ;
7-
8- #[ derive( Debug , Clone , ValueEnum ) ]
9- pub enum Provider {
10- Zenodo ,
11- }
7+ use tabled:: builder:: Builder ;
128
139#[ derive( Debug , Snafu ) ]
1410pub enum Error {
@@ -22,29 +18,82 @@ pub enum Error {
2218/// Copies the data from a location into a data deposit
2319#[ derive( Parser , Debug ) ]
2420pub struct CopyInput {
25- /// The id of the deposit the data should be copied to.
26- #[ arg( ) ]
27- pub deposit_id : String ,
28-
29- /// The provider for the dataset
30- #[ arg( ) ]
31- pub provider : Provider ,
32-
3321 /// The source directory where the files to be copied can be found.
3422 #[ arg( ) ]
3523 pub source_dir : PathBuf ,
24+
25+ /// The id of the deposit the data should be copied to.
26+ #[ arg( ) ]
27+ pub deposit_id : String ,
3628}
3729
3830impl CopyInput {
39- pub async fn exec ( & self , _ctx : Context ) -> Result < ( ) , Error > {
40- match self . provider {
31+ pub async fn exec ( & self , ctx : Context ) -> Result < ( ) , Error > {
32+ match ctx . provider {
4133 Provider :: Zenodo => {
4234 let token = std:: env:: var ( "ZENODO_API_KEY" ) . context ( EnvVarMissingSnafu ) ?;
43- let clnt = zenodo:: ZenodoClient :: new ( token) ;
35+ let clnt = zenodo:: ZenodoClient :: new ( token, ctx . parent . opts . verbose > 1 ) ;
4436 clnt. upload_files ( & self . deposit_id , & self . source_dir )
4537 . await
4638 . context ( ZenodoSnafu )
4739 }
4840 }
4941 }
5042}
43+
44+ /// List all depositions for the specific provider
45+ #[ derive( Parser , Debug ) ]
46+ pub struct ListInput { }
47+
48+ impl ListInput {
49+ pub async fn exec ( & self , ctx : Context ) -> Result < ( ) , Error > {
50+ match ctx. provider {
51+ Provider :: Zenodo => {
52+ let token = std:: env:: var ( "ZENODO_API_KEY" ) . context ( EnvVarMissingSnafu ) ?;
53+ let clnt = zenodo:: ZenodoClient :: new ( token, ctx. parent . opts . verbose > 1 ) ;
54+ let deps = clnt. get_depositions ( ) . await . context ( ZenodoSnafu ) ?;
55+ let mut table = Builder :: default ( ) ;
56+ table. push_record ( [ "ID" , "Title" , "State" , "Created at" ] ) ;
57+ for d in deps {
58+ table. push_record ( [
59+ d. id . to_string ( ) ,
60+ d. title ,
61+ d. state ,
62+ d. created
63+ . to_rfc3339_opts ( chrono:: SecondsFormat :: Secs , false ) ,
64+ ] ) ;
65+ }
66+ println ! ( "{}" , table. build( ) ) ;
67+ Ok ( ( ) )
68+ }
69+ }
70+ }
71+ }
72+
73+ /// List all files in a specific deposit
74+ #[ derive( Parser , Debug ) ]
75+ pub struct ListFiles {
76+ deposit_id : String ,
77+ }
78+
79+ impl ListFiles {
80+ pub async fn exec ( & self , ctx : Context ) -> Result < ( ) , Error > {
81+ match ctx. provider {
82+ Provider :: Zenodo => {
83+ let token = std:: env:: var ( "ZENODO_API_KEY" ) . context ( EnvVarMissingSnafu ) ?;
84+ let clnt = zenodo:: ZenodoClient :: new ( token, ctx. parent . opts . verbose > 1 ) ;
85+ let files = clnt
86+ . list_files ( & self . deposit_id )
87+ . await
88+ . context ( ZenodoSnafu ) ?;
89+ let mut table = Builder :: default ( ) ;
90+ table. push_record ( [ "Filename" , "Size" , "Checksum" ] ) ;
91+ for f in files {
92+ table. push_record ( [ f. filename , f. filesize . to_string ( ) , f. checksum ] ) ;
93+ }
94+ println ! ( "{}" , table. build( ) ) ;
95+ Ok ( ( ) )
96+ }
97+ }
98+ }
99+ }
0 commit comments