File size: 3,444 Bytes
d2948d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use clap::{Args, Parser, Subcommand, ValueEnum};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum OutputFormat {
    #[default]
    Json,
    Table,
    Plain,
}

#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum Network {
    #[default]
    Devnet,
    Mainnet,
}

#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum Asset {
    #[default]
    Sol,
    Usdc,
}

#[derive(Debug, Parser, Clone)]
#[command(
    name = "card-cli",
    version,
    about = "Agent-first virtual card CLI funded by Solana"
)]
pub struct Cli {
    #[arg(long, global = true)]
    pub format: Option<OutputFormat>,
    #[arg(long, global = true)]
    pub network: Option<Network>,
    #[arg(long, global = true)]
    pub api_key: Option<String>,
    #[arg(long, global = true, default_value_t = false)]
    pub quiet: bool,
    #[arg(long, global = true)]
    pub idempotency_key: Option<String>,
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Debug, Subcommand, Clone)]
pub enum Commands {
    Auth {
        #[command(subcommand)]
        command: AuthCommands,
    },
    Deposit {
        #[command(subcommand)]
        command: DepositCommands,
    },
    Card {
        #[command(subcommand)]
        command: CardCommands,
    },
    Balance,
    Config {
        #[command(subcommand)]
        command: ConfigCommands,
    },
    #[command(hide = true)]
    Debug {
        #[command(subcommand)]
        command: DebugCommands,
    },
}

#[derive(Debug, Subcommand, Clone)]
pub enum AuthCommands {
    Login(AuthLoginArgs),
    Status,
}

#[derive(Debug, Args, Clone)]
pub struct AuthLoginArgs {
    #[arg(long)]
    pub api_key: Option<String>,
}

#[derive(Debug, Subcommand, Clone)]
pub enum DepositCommands {
    Address(DepositAddressArgs),
    Status(DepositStatusArgs),
    List,
}

#[derive(Debug, Args, Clone)]
pub struct DepositAddressArgs {
    #[arg(long, value_enum, default_value_t = Asset::Sol)]
    pub asset: Asset,
}

#[derive(Debug, Args, Clone)]
pub struct DepositStatusArgs {
    pub id: String,
    #[arg(long, default_value_t = false)]
    pub wait: bool,
    #[arg(long, default_value_t = 300)]
    pub timeout: u64,
}

#[derive(Debug, Subcommand, Clone)]
pub enum CardCommands {
    Buy(CardBuyArgs),
    Show(CardShowArgs),
    List,
    Freeze(CardFreezeArgs),
}

#[derive(Debug, Args, Clone)]
pub struct CardBuyArgs {
    #[arg(long)]
    pub amount: String,
}

#[derive(Debug, Args, Clone)]
pub struct CardShowArgs {
    pub id: String,
}

#[derive(Debug, Args, Clone)]
pub struct CardFreezeArgs {
    pub id: String,
    #[arg(long, default_value_t = false)]
    pub confirm: bool,
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
}

#[derive(Debug, Subcommand, Clone)]
pub enum ConfigCommands {
    Set(ConfigSetArgs),
}

#[derive(Debug, Args, Clone)]
pub struct ConfigSetArgs {
    pub key: String,
    pub value: String,
}

#[derive(Debug, Subcommand, Clone)]
pub enum DebugCommands {
    ConfirmDeposit(DebugConfirmDepositArgs),
}

#[derive(Debug, Args, Clone)]
pub struct DebugConfirmDepositArgs {
    pub id: String,
    #[arg(long)]
    pub amount_usd: String,
    #[arg(long)]
    pub amount_native: Option<String>,
}