-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.rs
More file actions
80 lines (71 loc) · 1.96 KB
/
dataset.rs
File metadata and controls
80 lines (71 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pub mod deposit;
pub mod zenodo;
mod zenodo_api;
use super::Context as ParentContext;
use clap::{Parser, ValueEnum};
use snafu::{ResultExt, Snafu};
#[derive(Debug, Clone, ValueEnum)]
pub enum Provider {
Zenodo,
}
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Error with deposit: {}", source))]
Deposit { source: deposit::Error },
}
/// Sub command for managing datasets
#[derive(Parser, Debug)]
pub struct Input {
#[command(subcommand)]
pub subcmd: DatasetCommand,
}
#[derive(Parser, Debug)]
pub enum DatasetCommand {
Deposit {
#[arg(long, default_value = "zenodo")]
provider: Provider,
#[command(subcommand)]
cmd: DepositCommand,
},
}
#[derive(Parser, Debug)]
pub enum DepositCommand {
#[command(name = "cp")]
CopyFiles(deposit::CopyInput),
#[command(name = "ls")]
ListDeposits(deposit::ListInput),
#[command(name = "lsf")]
ListFiles(deposit::ListFiles),
}
pub struct Context {
pub parent: ParentContext,
pub provider: Provider,
}
impl Context {
pub fn new(ctx: ParentContext, provider: Provider) -> Context {
Context {
parent: ctx,
provider,
}
}
}
impl Input {
pub async fn exec(&self, ctx: ParentContext) -> Result<(), Error> {
match &self.subcmd {
DatasetCommand::Deposit { provider, cmd } => match cmd {
DepositCommand::CopyFiles(input) => input
.exec(Context::new(ctx, provider.clone()))
.await
.context(DepositSnafu),
DepositCommand::ListDeposits(input) => input
.exec(Context::new(ctx, provider.clone()))
.await
.context(DepositSnafu),
DepositCommand::ListFiles(input) => input
.exec(Context::new(ctx, provider.clone()))
.await
.context(DepositSnafu),
},
}
}
}