use serde::{Deserialize, Serialize};
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
pub enum Command {
#[structopt(name = "server")]
Server,
#[structopt(name = "status")]
Status,
#[structopt(name = "node")]
Node(NodeOperation),
#[structopt(name = "layout")]
Layout(LayoutOperation),
#[structopt(name = "bucket")]
Bucket(BucketOperation),
#[structopt(name = "key")]
Key(KeyOperation),
#[structopt(name = "repair")]
Repair(RepairOpt),
#[structopt(name = "stats")]
Stats(StatsOpt),
}
#[derive(StructOpt, Debug)]
pub enum NodeOperation {
#[structopt(name = "id")]
NodeId(NodeIdOpt),
#[structopt(name = "connect")]
Connect(ConnectNodeOpt),
}
#[derive(StructOpt, Debug)]
pub struct NodeIdOpt {
#[structopt(short = "q", long = "quiet")]
pub(crate) quiet: bool,
}
#[derive(StructOpt, Debug)]
pub struct ConnectNodeOpt {
pub(crate) node: String,
}
#[derive(StructOpt, Debug)]
pub enum LayoutOperation {
#[structopt(name = "assign")]
Assign(AssignRoleOpt),
#[structopt(name = "remove")]
Remove(RemoveRoleOpt),
#[structopt(name = "show")]
Show,
#[structopt(name = "apply")]
Apply(ApplyLayoutOpt),
#[structopt(name = "revert")]
Revert(RevertLayoutOpt),
}
#[derive(StructOpt, Debug)]
pub struct AssignRoleOpt {
pub(crate) node_id: String,
#[structopt(short = "z", long = "zone")]
pub(crate) zone: Option<String>,
#[structopt(short = "c", long = "capacity")]
pub(crate) capacity: Option<u32>,
#[structopt(short = "g", long = "gateway")]
pub(crate) gateway: bool,
#[structopt(short = "t", long = "tag")]
pub(crate) tags: Vec<String>,
#[structopt(long = "replace")]
pub(crate) replace: Vec<String>,
}
#[derive(StructOpt, Debug)]
pub struct RemoveRoleOpt {
pub(crate) node_id: String,
}
#[derive(StructOpt, Debug)]
pub struct ApplyLayoutOpt {
#[structopt(long = "version")]
pub(crate) version: Option<u64>,
}
#[derive(StructOpt, Debug)]
pub struct RevertLayoutOpt {
#[structopt(long = "version")]
pub(crate) version: Option<u64>,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub enum BucketOperation {
#[structopt(name = "list")]
List,
#[structopt(name = "info")]
Info(BucketOpt),
#[structopt(name = "create")]
Create(BucketOpt),
#[structopt(name = "delete")]
Delete(DeleteBucketOpt),
#[structopt(name = "allow")]
Allow(PermBucketOpt),
#[structopt(name = "deny")]
Deny(PermBucketOpt),
#[structopt(name = "website")]
Website(WebsiteOpt),
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct WebsiteOpt {
#[structopt(long = "allow")]
pub allow: bool,
#[structopt(long = "deny")]
pub deny: bool,
pub bucket: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct BucketOpt {
pub name: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct DeleteBucketOpt {
pub name: String,
#[structopt(long = "yes")]
pub yes: bool,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct PermBucketOpt {
#[structopt(long = "key")]
pub key_pattern: String,
#[structopt(long = "read")]
pub read: bool,
#[structopt(long = "write")]
pub write: bool,
pub bucket: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub enum KeyOperation {
#[structopt(name = "list")]
List,
#[structopt(name = "info")]
Info(KeyOpt),
#[structopt(name = "new")]
New(KeyNewOpt),
#[structopt(name = "rename")]
Rename(KeyRenameOpt),
#[structopt(name = "delete")]
Delete(KeyDeleteOpt),
#[structopt(name = "import")]
Import(KeyImportOpt),
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct KeyOpt {
pub key_pattern: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct KeyNewOpt {
#[structopt(long = "name", default_value = "Unnamed key")]
pub name: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct KeyRenameOpt {
pub key_pattern: String,
pub new_name: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct KeyDeleteOpt {
pub key_pattern: String,
#[structopt(long = "yes")]
pub yes: bool,
}
#[derive(Serialize, Deserialize, StructOpt, Debug)]
pub struct KeyImportOpt {
pub key_id: String,
pub secret_key: String,
#[structopt(short = "n", default_value = "Imported key")]
pub name: String,
}
#[derive(Serialize, Deserialize, StructOpt, Debug, Clone)]
pub struct RepairOpt {
#[structopt(short = "a", long = "all-nodes")]
pub all_nodes: bool,
#[structopt(long = "yes")]
pub yes: bool,
#[structopt(subcommand)]
pub what: RepairWhat,
}
#[derive(Serialize, Deserialize, StructOpt, Debug, Eq, PartialEq, Clone)]
pub enum RepairWhat {
#[structopt(name = "tables")]
Tables,
#[structopt(name = "blocks")]
Blocks,
#[structopt(name = "versions")]
Versions,
#[structopt(name = "block_refs")]
BlockRefs,
#[structopt(name = "scrub")]
Scrub {
#[structopt(name = "tranquility", default_value = "2")]
tranquility: u32,
},
}
#[derive(Serialize, Deserialize, StructOpt, Debug, Clone)]
pub struct StatsOpt {
#[structopt(short = "a", long = "all-nodes")]
pub all_nodes: bool,
#[structopt(short = "d", long = "detailed")]
pub detailed: bool,
}