cli

Command-line interface for Radroots
git clone https://radroots.dev/git/cli.git
Log | Files | Refs | README | LICENSE

commit b631bd4920080404e45e1336859abf82c2e39898
parent 3d132a9ae8b0ad07091a12e6c5b3e3d64e2c7644
Author: triesap <tyson@radroots.org>
Date:   Tue, 26 May 2026 20:16:54 +0000

cli: split command parser modules

Diffstat:
Asrc/cli/account.rs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/basket.rs | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/config.rs | 12++++++++++++
Asrc/cli/farm.rs | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/health.rs | 35+++++++++++++++++++++++++++++++++++
Asrc/cli/input.rs | 372+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/listing.rs | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/market.rs | 43+++++++++++++++++++++++++++++++++++++++++++
Msrc/cli/mod.rs | 915+++----------------------------------------------------------------------------
Asrc/cli/order.rs | 264+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/relay.rs | 12++++++++++++
Asrc/cli/signer.rs | 23+++++++++++++++++++++++
Asrc/cli/store.rs | 37+++++++++++++++++++++++++++++++++++++
Asrc/cli/sync.rs | 26++++++++++++++++++++++++++
Asrc/cli/validation.rs | 44++++++++++++++++++++++++++++++++++++++++++++
Asrc/cli/workspace.rs | 13+++++++++++++
Msrc/main.rs | 38++------------------------------------
Msrc/ops/mod.rs | 334+------------------------------------------------------------------------------
18 files changed, 1311 insertions(+), 1251 deletions(-)

diff --git a/src/cli/account.rs b/src/cli/account.rs @@ -0,0 +1,58 @@ +use std::path::PathBuf; + +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct AccountArgs { + #[command(subcommand)] + pub command: AccountCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum AccountCommand { + Create, + Import(AccountImportArgs), + AttachSecret(AccountAttachSecretArgs), + Get(AccountGetArgs), + List, + Remove(AccountSelectorArgs), + Selection(AccountSelectionArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct AccountImportArgs { + pub path: Option<PathBuf>, + #[arg(long, action = clap::ArgAction::SetTrue)] + pub default: bool, +} + +#[derive(Debug, Clone, Args)] +pub struct AccountAttachSecretArgs { + pub selector: Option<String>, + pub path: Option<PathBuf>, + #[arg(long, action = clap::ArgAction::SetTrue)] + pub default: bool, +} + +#[derive(Debug, Clone, Args)] +pub struct AccountGetArgs { + pub selector: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct AccountSelectorArgs { + pub selector: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct AccountSelectionArgs { + #[command(subcommand)] + pub command: AccountSelectionCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum AccountSelectionCommand { + Get, + Update(AccountSelectorArgs), + Clear, +} diff --git a/src/cli/basket.rs b/src/cli/basket.rs @@ -0,0 +1,115 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct BasketArgs { + #[command(subcommand)] + pub command: BasketCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum BasketCommand { + Create(BasketCreateArgs), + Get(BasketKeyArgs), + List, + Item(BasketItemArgs), + Adjustment(BasketAdjustmentArgs), + Validate(BasketKeyArgs), + Quote(BasketQuoteArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct BasketCreateArgs { + pub basket_id: Option<String>, + #[arg(long)] + pub listing: Option<String>, + #[arg(long = "listing-addr")] + pub listing_addr: Option<String>, + #[arg(long = "bin-id")] + pub bin_id: Option<String>, + #[arg(long)] + pub quantity: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketKeyArgs { + pub basket_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketItemArgs { + #[command(subcommand)] + pub command: BasketItemCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum BasketItemCommand { + Add(BasketItemMutationArgs), + Update(BasketItemMutationArgs), + Remove(BasketItemRemoveArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct BasketAdjustmentArgs { + #[command(subcommand)] + pub command: BasketAdjustmentCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum BasketAdjustmentCommand { + Add(BasketAdjustmentAddArgs), + Remove(BasketAdjustmentRemoveArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct BasketAdjustmentAddArgs { + pub basket_id: Option<String>, + #[arg(long)] + pub id: Option<String>, + #[arg(long)] + pub effect: Option<String>, + #[arg(long)] + pub amount: Option<String>, + #[arg(long)] + pub currency: Option<String>, + #[arg(long)] + pub reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketAdjustmentRemoveArgs { + pub basket_id: Option<String>, + #[arg(long)] + pub id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketItemMutationArgs { + pub basket_id: Option<String>, + #[arg(long = "item-id")] + pub item_id: Option<String>, + #[arg(long)] + pub listing: Option<String>, + #[arg(long = "listing-addr")] + pub listing_addr: Option<String>, + #[arg(long = "bin-id")] + pub bin_id: Option<String>, + #[arg(long)] + pub quantity: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketItemRemoveArgs { + pub basket_id: Option<String>, + pub item_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct BasketQuoteArgs { + #[command(subcommand)] + pub command: BasketQuoteCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum BasketQuoteCommand { + Create(BasketKeyArgs), +} diff --git a/src/cli/config.rs b/src/cli/config.rs @@ -0,0 +1,12 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct ConfigArgs { + #[command(subcommand)] + pub command: ConfigCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum ConfigCommand { + Get, +} diff --git a/src/cli/farm.rs b/src/cli/farm.rs @@ -0,0 +1,118 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct FarmArgs { + #[command(subcommand)] + pub command: FarmCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum FarmCommand { + Create(FarmCreateArgs), + Get, + Rebind(FarmRebindArgs), + Profile(FarmProfileArgs), + Location(FarmLocationArgs), + Fulfillment(FarmFulfillmentArgs), + Readiness(FarmReadinessArgs), + Publish, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmCreateArgs { + #[arg(long = "farm-d-tag")] + pub farm_d_tag: Option<String>, + #[arg(long)] + pub name: Option<String>, + #[arg(long = "display-name")] + pub display_name: Option<String>, + #[arg(long)] + pub about: Option<String>, + #[arg(long)] + pub website: Option<String>, + #[arg(long)] + pub picture: Option<String>, + #[arg(long)] + pub banner: Option<String>, + #[arg(long)] + pub location: Option<String>, + #[arg(long)] + pub city: Option<String>, + #[arg(long)] + pub region: Option<String>, + #[arg(long)] + pub country: Option<String>, + #[arg(long = "delivery-method")] + pub delivery_method: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmRebindArgs { + pub selector: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmProfileArgs { + #[command(subcommand)] + pub command: FarmProfileCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum FarmProfileCommand { + Update(FarmProfileUpdateArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct FarmProfileUpdateArgs { + #[arg(long)] + pub field: Option<String>, + #[arg(long)] + pub value: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmLocationArgs { + #[command(subcommand)] + pub command: FarmLocationCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum FarmLocationCommand { + Update(FarmLocationUpdateArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct FarmLocationUpdateArgs { + #[arg(long)] + pub field: Option<String>, + #[arg(long)] + pub value: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmFulfillmentArgs { + #[command(subcommand)] + pub command: FarmFulfillmentCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum FarmFulfillmentCommand { + Update(FarmFulfillmentUpdateArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct FarmFulfillmentUpdateArgs { + #[arg(long)] + pub value: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FarmReadinessArgs { + #[command(subcommand)] + pub command: FarmReadinessCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum FarmReadinessCommand { + Check, +} diff --git a/src/cli/health.rs b/src/cli/health.rs @@ -0,0 +1,35 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct HealthArgs { + #[command(subcommand)] + pub command: HealthCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum HealthCommand { + Status(HealthStatusArgs), + Check(HealthCheckArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct HealthStatusArgs { + #[command(subcommand)] + pub command: HealthStatusCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum HealthStatusCommand { + Get, +} + +#[derive(Debug, Clone, Args)] +pub struct HealthCheckArgs { + #[command(subcommand)] + pub command: HealthCheckCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum HealthCheckCommand { + Run, +} diff --git a/src/cli/input.rs b/src/cli/input.rs @@ -0,0 +1,372 @@ +use crate::cli::global::{RuntimeInvocationArgs, RuntimeOutputFormatArg}; +use crate::cli::{TargetCliArgs, TargetCommand, TargetOutputFormat}; +use crate::ops::OperationData; +use serde_json::Value; + +pub fn runtime_invocation_args_from_target(args: &TargetCliArgs) -> RuntimeInvocationArgs { + RuntimeInvocationArgs { + output_format: Some(match args.format { + TargetOutputFormat::Human => RuntimeOutputFormatArg::Human, + TargetOutputFormat::Json => RuntimeOutputFormatArg::Json, + TargetOutputFormat::Ndjson => RuntimeOutputFormatArg::Ndjson, + }), + json: false, + ndjson: false, + env_file: None, + quiet: args.quiet, + verbose: args.verbose, + trace: args.trace, + dry_run: args.dry_run, + no_color: args.no_color, + no_input: args.no_input, + yes: false, + log_filter: None, + log_dir: None, + log_stdout: false, + no_log_stdout: false, + account: args.account_id.clone(), + identity_path: None, + signer: None, + publish_mode: args.publish_mode.map(|mode| mode.as_str().to_owned()), + relay: args.relay.clone(), + myc_executable: None, + myc_status_timeout_ms: None, + hyf_enabled: false, + no_hyf_enabled: false, + hyf_executable: None, + } +} + +pub fn operation_id_from_target(args: &TargetCliArgs) -> &'static str { + args.command.operation_id() +} + +pub fn target_operation_input(command: &TargetCommand) -> OperationData { + use crate::cli::{ + AccountCommand, AccountSelectionCommand, BasketAdjustmentCommand, BasketCommand, + BasketItemCommand, BasketQuoteCommand, FarmCommand, FarmFulfillmentCommand, + FarmLocationCommand, FarmProfileCommand, ListingAppCommand, ListingCommand, MarketCommand, + MarketListingCommand, MarketProductCommand, OrderAppCommand, OrderCommand, + OrderEventCommand, OrderFulfillmentCommand, OrderPaymentCommand, OrderReceiptCommand, + OrderRevisionCommand, OrderSettlementCommand, OrderStatusCommand, ValidationCommand, + ValidationReceiptCommand, + }; + + let mut input = OperationData::new(); + match command { + TargetCommand::Account(args) => match &args.command { + AccountCommand::Import(args) => { + insert_path(&mut input, "path", &args.path); + if args.default { + input.insert("default".to_owned(), Value::Bool(true)); + } + } + AccountCommand::AttachSecret(args) => { + insert_string(&mut input, "selector", &args.selector); + insert_path(&mut input, "path", &args.path); + if args.default { + input.insert("default".to_owned(), Value::Bool(true)); + } + } + AccountCommand::Get(args) => insert_string(&mut input, "selector", &args.selector), + AccountCommand::Remove(args) => insert_string(&mut input, "selector", &args.selector), + AccountCommand::Selection(args) => match &args.command { + AccountSelectionCommand::Update(args) => { + insert_string(&mut input, "selector", &args.selector) + } + AccountSelectionCommand::Get | AccountSelectionCommand::Clear => {} + }, + AccountCommand::Create | AccountCommand::List => {} + }, + TargetCommand::Farm(args) => match &args.command { + FarmCommand::Create(args) => { + insert_string(&mut input, "farm_d_tag", &args.farm_d_tag); + insert_string(&mut input, "name", &args.name); + insert_string(&mut input, "display_name", &args.display_name); + insert_string(&mut input, "about", &args.about); + insert_string(&mut input, "website", &args.website); + insert_string(&mut input, "picture", &args.picture); + insert_string(&mut input, "banner", &args.banner); + insert_string(&mut input, "location", &args.location); + insert_string(&mut input, "city", &args.city); + insert_string(&mut input, "region", &args.region); + insert_string(&mut input, "country", &args.country); + insert_string(&mut input, "delivery_method", &args.delivery_method); + } + FarmCommand::Rebind(args) => { + insert_string(&mut input, "selector", &args.selector); + } + FarmCommand::Profile(args) => match &args.command { + FarmProfileCommand::Update(args) => { + insert_string(&mut input, "field", &args.field); + insert_string(&mut input, "value", &args.value); + } + }, + FarmCommand::Location(args) => match &args.command { + FarmLocationCommand::Update(args) => { + insert_string(&mut input, "field", &args.field); + insert_string(&mut input, "value", &args.value); + } + }, + FarmCommand::Fulfillment(args) => match &args.command { + FarmFulfillmentCommand::Update(args) => { + insert_string(&mut input, "value", &args.value); + } + }, + FarmCommand::Get | FarmCommand::Readiness(_) | FarmCommand::Publish => {} + }, + TargetCommand::Listing(args) => match &args.command { + ListingCommand::Create(args) => { + insert_path(&mut input, "output", &args.output); + insert_string(&mut input, "key", &args.key); + insert_string(&mut input, "title", &args.title); + insert_string(&mut input, "category", &args.category); + insert_string(&mut input, "summary", &args.summary); + insert_string(&mut input, "bin_id", &args.bin_id); + insert_string(&mut input, "quantity_amount", &args.quantity_amount); + insert_string(&mut input, "quantity_unit", &args.quantity_unit); + insert_string(&mut input, "price_amount", &args.price_amount); + insert_string(&mut input, "price_currency", &args.price_currency); + insert_string(&mut input, "price_per_amount", &args.price_per_amount); + insert_string(&mut input, "price_per_unit", &args.price_per_unit); + insert_string(&mut input, "available", &args.available); + insert_string(&mut input, "label", &args.label); + insert_string(&mut input, "discount_id", &args.discount_id); + insert_string(&mut input, "discount_label", &args.discount_label); + insert_string(&mut input, "discount_kind", &args.discount_kind); + insert_string(&mut input, "discount_value", &args.discount_value); + insert_string(&mut input, "discount_amount", &args.discount_amount); + insert_string(&mut input, "discount_currency", &args.discount_currency); + } + ListingCommand::Get(args) => insert_string(&mut input, "key", &args.key), + ListingCommand::App(args) => match &args.command { + ListingAppCommand::Export(args) => { + insert_string(&mut input, "record_id", &args.record_id); + insert_path(&mut input, "output", &args.output); + } + ListingAppCommand::List => {} + }, + ListingCommand::Update(args) + | ListingCommand::Validate(args) + | ListingCommand::Publish(args) + | ListingCommand::Archive(args) => insert_path(&mut input, "file", &args.file), + ListingCommand::Rebind(args) => { + insert_path(&mut input, "file", &args.file); + insert_string(&mut input, "selector", &args.selector); + insert_string(&mut input, "farm_d_tag", &args.farm_d_tag); + } + ListingCommand::List => {} + }, + TargetCommand::Market(args) => match &args.command { + MarketCommand::Product(product) => match &product.command { + MarketProductCommand::Search(args) => { + insert_string_array(&mut input, "query", args.query.as_slice()) + } + }, + MarketCommand::Listing(listing) => match &listing.command { + MarketListingCommand::Get(args) => insert_string(&mut input, "key", &args.key), + }, + MarketCommand::Refresh => {} + }, + TargetCommand::Basket(args) => match &args.command { + BasketCommand::Create(args) => { + insert_string(&mut input, "basket_id", &args.basket_id); + insert_string(&mut input, "listing", &args.listing); + insert_string(&mut input, "listing_addr", &args.listing_addr); + insert_string(&mut input, "bin_id", &args.bin_id); + insert_string(&mut input, "quantity", &args.quantity); + } + BasketCommand::Get(args) | BasketCommand::Validate(args) => { + insert_string(&mut input, "basket_id", &args.basket_id) + } + BasketCommand::Item(item) => match &item.command { + BasketItemCommand::Add(args) | BasketItemCommand::Update(args) => { + insert_string(&mut input, "basket_id", &args.basket_id); + insert_string(&mut input, "item_id", &args.item_id); + insert_string(&mut input, "listing", &args.listing); + insert_string(&mut input, "listing_addr", &args.listing_addr); + insert_string(&mut input, "bin_id", &args.bin_id); + insert_string(&mut input, "quantity", &args.quantity); + } + BasketItemCommand::Remove(args) => { + insert_string(&mut input, "basket_id", &args.basket_id); + insert_string(&mut input, "item_id", &args.item_id); + } + }, + BasketCommand::Adjustment(adjustment) => match &adjustment.command { + BasketAdjustmentCommand::Add(args) => { + insert_string(&mut input, "basket_id", &args.basket_id); + insert_string(&mut input, "id", &args.id); + insert_string(&mut input, "effect", &args.effect); + insert_string(&mut input, "amount", &args.amount); + insert_string(&mut input, "currency", &args.currency); + insert_string(&mut input, "reason", &args.reason); + } + BasketAdjustmentCommand::Remove(args) => { + insert_string(&mut input, "basket_id", &args.basket_id); + insert_string(&mut input, "id", &args.id); + } + }, + BasketCommand::Quote(quote) => match &quote.command { + BasketQuoteCommand::Create(args) => { + insert_string(&mut input, "basket_id", &args.basket_id) + } + }, + BasketCommand::List => {} + }, + TargetCommand::Order(args) => match &args.command { + OrderCommand::Submit(args) => { + insert_string(&mut input, "order_id", &args.order_id); + } + OrderCommand::Get(args) => insert_string(&mut input, "order_id", &args.order_id), + OrderCommand::App(args) => match &args.command { + OrderAppCommand::Export(args) => { + insert_string(&mut input, "record_id", &args.record_id); + insert_path(&mut input, "output", &args.output); + } + OrderAppCommand::List => {} + }, + OrderCommand::Rebind(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "selector", &args.selector); + } + OrderCommand::Accept(args) => insert_string(&mut input, "order_id", &args.order_id), + OrderCommand::Decline(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "reason", &args.reason); + } + OrderCommand::Cancel(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "reason", &args.reason); + } + OrderCommand::Revision(revision) => match &revision.command { + OrderRevisionCommand::Propose(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "reason", &args.reason); + insert_string(&mut input, "bin_id", &args.bin_id); + if let Some(bin_count) = args.bin_count { + input.insert( + "bin_count".to_owned(), + Value::Number(serde_json::Number::from(bin_count)), + ); + } + insert_string(&mut input, "adjustment_id", &args.adjustment_id); + insert_string(&mut input, "adjustment_effect", &args.adjustment_effect); + insert_string(&mut input, "adjustment_amount", &args.adjustment_amount); + insert_string(&mut input, "adjustment_currency", &args.adjustment_currency); + insert_string(&mut input, "adjustment_reason", &args.adjustment_reason); + } + OrderRevisionCommand::Accept(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "revision_id", &args.revision_id); + } + OrderRevisionCommand::Decline(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "revision_id", &args.revision_id); + insert_string(&mut input, "reason", &args.reason); + } + }, + OrderCommand::Fulfillment(fulfillment) => match &fulfillment.command { + OrderFulfillmentCommand::Update(args) => { + insert_string(&mut input, "order_id", &args.order_id); + if let Some(state) = args.state { + input.insert( + "state".to_owned(), + Value::String(state.as_protocol_state().to_owned()), + ); + } + } + }, + OrderCommand::Receipt(receipt) => match &receipt.command { + OrderReceiptCommand::Record(args) => { + insert_string(&mut input, "order_id", &args.order_id); + if args.received { + input.insert("received".to_owned(), Value::Bool(true)); + } + insert_string(&mut input, "issue", &args.issue); + } + }, + OrderCommand::Payment(payment) => match &payment.command { + OrderPaymentCommand::Record(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "amount", &args.amount); + insert_string(&mut input, "currency", &args.currency); + insert_string(&mut input, "method", &args.method); + insert_string(&mut input, "reference", &args.reference); + if let Some(paid_at) = args.paid_at { + input.insert( + "paid_at".to_owned(), + Value::Number(serde_json::Number::from(paid_at)), + ); + } + } + }, + OrderCommand::Settlement(settlement) => match &settlement.command { + OrderSettlementCommand::Accept(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "payment_event_id", &args.payment_event_id); + } + OrderSettlementCommand::Reject(args) => { + insert_string(&mut input, "order_id", &args.order_id); + insert_string(&mut input, "payment_event_id", &args.payment_event_id); + insert_string(&mut input, "reason", &args.reason); + } + }, + OrderCommand::Status(status) => match &status.command { + OrderStatusCommand::Get(args) => { + insert_string(&mut input, "order_id", &args.order_id) + } + }, + OrderCommand::Event(event) => match &event.command { + OrderEventCommand::List(args) | OrderEventCommand::Watch(args) => { + insert_string(&mut input, "order_id", &args.order_id) + } + }, + OrderCommand::List => {} + }, + TargetCommand::Validation(args) => match &args.command { + ValidationCommand::Receipt(receipt) => match &receipt.command { + ValidationReceiptCommand::Get(args) | ValidationReceiptCommand::Verify(args) => { + insert_string(&mut input, "receipt_event_id", &args.receipt_event_id); + } + ValidationReceiptCommand::List(args) => { + insert_string(&mut input, "order_id", &args.order_id); + } + }, + }, + _ => {} + } + input +} + +fn insert_string(input: &mut OperationData, key: &str, value: &Option<String>) { + if let Some(value) = value + .as_deref() + .map(str::trim) + .filter(|value| !value.is_empty()) + { + input.insert(key.to_owned(), Value::String(value.to_owned())); + } +} + +fn insert_string_array(input: &mut OperationData, key: &str, values: &[String]) { + let values = values + .iter() + .map(String::as_str) + .map(str::trim) + .filter(|value| !value.is_empty()) + .map(|value| Value::String(value.to_owned())) + .collect::<Vec<_>>(); + if !values.is_empty() { + input.insert(key.to_owned(), Value::Array(values)); + } +} + +fn insert_path(input: &mut OperationData, key: &str, value: &Option<std::path::PathBuf>) { + if let Some(value) = value { + input.insert( + key.to_owned(), + Value::String(value.to_string_lossy().into_owned()), + ); + } +} diff --git a/src/cli/listing.rs b/src/cli/listing.rs @@ -0,0 +1,103 @@ +use std::path::PathBuf; + +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct ListingArgs { + #[command(subcommand)] + pub command: ListingCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum ListingCommand { + Create(ListingCreateArgs), + Get(LookupArgs), + List, + App(ListingAppArgs), + Update(FileArgs), + Validate(FileArgs), + Rebind(ListingRebindArgs), + Publish(FileArgs), + Archive(FileArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct ListingCreateArgs { + #[arg(long)] + pub output: Option<PathBuf>, + #[arg(long)] + pub key: Option<String>, + #[arg(long)] + pub title: Option<String>, + #[arg(long)] + pub category: Option<String>, + #[arg(long)] + pub summary: Option<String>, + #[arg(long = "bin-id")] + pub bin_id: Option<String>, + #[arg(long = "quantity-amount")] + pub quantity_amount: Option<String>, + #[arg(long = "quantity-unit")] + pub quantity_unit: Option<String>, + #[arg(long = "price-amount")] + pub price_amount: Option<String>, + #[arg(long = "price-currency")] + pub price_currency: Option<String>, + #[arg(long = "price-per-amount")] + pub price_per_amount: Option<String>, + #[arg(long = "price-per-unit")] + pub price_per_unit: Option<String>, + #[arg(long)] + pub available: Option<String>, + #[arg(long)] + pub label: Option<String>, + #[arg(long = "discount-id")] + pub discount_id: Option<String>, + #[arg(long = "discount-label")] + pub discount_label: Option<String>, + #[arg(long = "discount-kind")] + pub discount_kind: Option<String>, + #[arg(long = "discount-value")] + pub discount_value: Option<String>, + #[arg(long = "discount-amount")] + pub discount_amount: Option<String>, + #[arg(long = "discount-currency")] + pub discount_currency: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct FileArgs { + pub file: Option<PathBuf>, +} + +#[derive(Debug, Clone, Args)] +pub struct ListingAppArgs { + #[command(subcommand)] + pub command: ListingAppCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum ListingAppCommand { + List, + Export(ListingAppExportArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct ListingAppExportArgs { + pub record_id: Option<String>, + #[arg(long)] + pub output: Option<PathBuf>, +} + +#[derive(Debug, Clone, Args)] +pub struct ListingRebindArgs { + pub file: Option<PathBuf>, + pub selector: Option<String>, + #[arg(long = "farm-d-tag")] + pub farm_d_tag: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct LookupArgs { + pub key: Option<String>, +} diff --git a/src/cli/market.rs b/src/cli/market.rs @@ -0,0 +1,43 @@ +use clap::{Args, Subcommand}; + +use crate::cli::listing::LookupArgs; + +#[derive(Debug, Clone, Args)] +pub struct MarketArgs { + #[command(subcommand)] + pub command: MarketCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum MarketCommand { + Refresh, + Product(MarketProductArgs), + Listing(MarketListingArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct MarketProductArgs { + #[command(subcommand)] + pub command: MarketProductCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum MarketProductCommand { + Search(QueryArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct MarketListingArgs { + #[command(subcommand)] + pub command: MarketListingCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum MarketListingCommand { + Get(LookupArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct QueryArgs { + pub query: Vec<String>, +} diff --git a/src/cli/mod.rs b/src/cli/mod.rs @@ -2,9 +2,38 @@ pub mod global; -use std::path::PathBuf; - -use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum}; +pub mod account; +pub mod basket; +pub mod config; +pub mod farm; +pub mod health; +pub mod input; +pub mod listing; +pub mod market; +pub mod order; +pub mod relay; +pub mod signer; +pub mod store; +pub mod sync; +pub mod validation; +pub mod workspace; + +pub use account::*; +pub use basket::*; +pub use config::*; +pub use farm::*; +pub use health::*; +pub use listing::*; +pub use market::*; +pub use order::*; +pub use relay::*; +pub use signer::*; +pub use store::*; +pub use sync::*; +pub use validation::*; +pub use workspace::*; + +use clap::{ArgAction, Parser, Subcommand, ValueEnum}; #[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)] pub enum TargetOutputFormat { @@ -272,886 +301,6 @@ impl TargetCommand { } } } - -#[derive(Debug, Clone, Args)] -pub struct WorkspaceArgs { - #[command(subcommand)] - pub command: WorkspaceCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum WorkspaceCommand { - Init, - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct HealthArgs { - #[command(subcommand)] - pub command: HealthCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum HealthCommand { - Status(HealthStatusArgs), - Check(HealthCheckArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct HealthStatusArgs { - #[command(subcommand)] - pub command: HealthStatusCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum HealthStatusCommand { - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct HealthCheckArgs { - #[command(subcommand)] - pub command: HealthCheckCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum HealthCheckCommand { - Run, -} - -#[derive(Debug, Clone, Args)] -pub struct ConfigArgs { - #[command(subcommand)] - pub command: ConfigCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum ConfigCommand { - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct AccountArgs { - #[command(subcommand)] - pub command: AccountCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum AccountCommand { - Create, - Import(AccountImportArgs), - AttachSecret(AccountAttachSecretArgs), - Get(AccountGetArgs), - List, - Remove(AccountSelectorArgs), - Selection(AccountSelectionArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct AccountImportArgs { - pub path: Option<PathBuf>, - #[arg(long, action = clap::ArgAction::SetTrue)] - pub default: bool, -} - -#[derive(Debug, Clone, Args)] -pub struct AccountAttachSecretArgs { - pub selector: Option<String>, - pub path: Option<PathBuf>, - #[arg(long, action = clap::ArgAction::SetTrue)] - pub default: bool, -} - -#[derive(Debug, Clone, Args)] -pub struct AccountGetArgs { - pub selector: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct AccountSelectorArgs { - pub selector: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct AccountSelectionArgs { - #[command(subcommand)] - pub command: AccountSelectionCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum AccountSelectionCommand { - Get, - Update(AccountSelectorArgs), - Clear, -} - -#[derive(Debug, Clone, Args)] -pub struct SignerArgs { - #[command(subcommand)] - pub command: SignerCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum SignerCommand { - Status(SignerStatusArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct SignerStatusArgs { - #[command(subcommand)] - pub command: SignerStatusCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum SignerStatusCommand { - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct RelayArgs { - #[command(subcommand)] - pub command: RelayCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum RelayCommand { - List, -} - -#[derive(Debug, Clone, Args)] -pub struct StoreArgs { - #[command(subcommand)] - pub command: StoreCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum StoreCommand { - Init, - Status(StoreStatusArgs), - Export, - Backup(StoreBackupArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct StoreStatusArgs { - #[command(subcommand)] - pub command: StoreStatusCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum StoreStatusCommand { - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct StoreBackupArgs { - #[command(subcommand)] - pub command: StoreBackupCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum StoreBackupCommand { - Create, -} - -#[derive(Debug, Clone, Args)] -pub struct SyncArgs { - #[command(subcommand)] - pub command: SyncCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum SyncCommand { - Status(SyncStatusArgs), - Pull, - Push, - Watch, -} - -#[derive(Debug, Clone, Args)] -pub struct SyncStatusArgs { - #[command(subcommand)] - pub command: SyncStatusCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum SyncStatusCommand { - Get, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmArgs { - #[command(subcommand)] - pub command: FarmCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum FarmCommand { - Create(FarmCreateArgs), - Get, - Rebind(FarmRebindArgs), - Profile(FarmProfileArgs), - Location(FarmLocationArgs), - Fulfillment(FarmFulfillmentArgs), - Readiness(FarmReadinessArgs), - Publish, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmCreateArgs { - #[arg(long = "farm-d-tag")] - pub farm_d_tag: Option<String>, - #[arg(long)] - pub name: Option<String>, - #[arg(long = "display-name")] - pub display_name: Option<String>, - #[arg(long)] - pub about: Option<String>, - #[arg(long)] - pub website: Option<String>, - #[arg(long)] - pub picture: Option<String>, - #[arg(long)] - pub banner: Option<String>, - #[arg(long)] - pub location: Option<String>, - #[arg(long)] - pub city: Option<String>, - #[arg(long)] - pub region: Option<String>, - #[arg(long)] - pub country: Option<String>, - #[arg(long = "delivery-method")] - pub delivery_method: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmRebindArgs { - pub selector: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmProfileArgs { - #[command(subcommand)] - pub command: FarmProfileCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum FarmProfileCommand { - Update(FarmProfileUpdateArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct FarmProfileUpdateArgs { - #[arg(long)] - pub field: Option<String>, - #[arg(long)] - pub value: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmLocationArgs { - #[command(subcommand)] - pub command: FarmLocationCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum FarmLocationCommand { - Update(FarmLocationUpdateArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct FarmLocationUpdateArgs { - #[arg(long)] - pub field: Option<String>, - #[arg(long)] - pub value: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmFulfillmentArgs { - #[command(subcommand)] - pub command: FarmFulfillmentCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum FarmFulfillmentCommand { - Update(FarmFulfillmentUpdateArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct FarmFulfillmentUpdateArgs { - #[arg(long)] - pub value: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FarmReadinessArgs { - #[command(subcommand)] - pub command: FarmReadinessCommand, -} - -#[derive(Debug, Clone, Copy, Subcommand)] -pub enum FarmReadinessCommand { - Check, -} - -#[derive(Debug, Clone, Args)] -pub struct ListingArgs { - #[command(subcommand)] - pub command: ListingCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum ListingCommand { - Create(ListingCreateArgs), - Get(LookupArgs), - List, - App(ListingAppArgs), - Update(FileArgs), - Validate(FileArgs), - Rebind(ListingRebindArgs), - Publish(FileArgs), - Archive(FileArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ListingCreateArgs { - #[arg(long)] - pub output: Option<PathBuf>, - #[arg(long)] - pub key: Option<String>, - #[arg(long)] - pub title: Option<String>, - #[arg(long)] - pub category: Option<String>, - #[arg(long)] - pub summary: Option<String>, - #[arg(long = "bin-id")] - pub bin_id: Option<String>, - #[arg(long = "quantity-amount")] - pub quantity_amount: Option<String>, - #[arg(long = "quantity-unit")] - pub quantity_unit: Option<String>, - #[arg(long = "price-amount")] - pub price_amount: Option<String>, - #[arg(long = "price-currency")] - pub price_currency: Option<String>, - #[arg(long = "price-per-amount")] - pub price_per_amount: Option<String>, - #[arg(long = "price-per-unit")] - pub price_per_unit: Option<String>, - #[arg(long)] - pub available: Option<String>, - #[arg(long)] - pub label: Option<String>, - #[arg(long = "discount-id")] - pub discount_id: Option<String>, - #[arg(long = "discount-label")] - pub discount_label: Option<String>, - #[arg(long = "discount-kind")] - pub discount_kind: Option<String>, - #[arg(long = "discount-value")] - pub discount_value: Option<String>, - #[arg(long = "discount-amount")] - pub discount_amount: Option<String>, - #[arg(long = "discount-currency")] - pub discount_currency: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct FileArgs { - pub file: Option<PathBuf>, -} - -#[derive(Debug, Clone, Args)] -pub struct ListingAppArgs { - #[command(subcommand)] - pub command: ListingAppCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum ListingAppCommand { - List, - Export(ListingAppExportArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ListingAppExportArgs { - pub record_id: Option<String>, - #[arg(long)] - pub output: Option<PathBuf>, -} - -#[derive(Debug, Clone, Args)] -pub struct ListingRebindArgs { - pub file: Option<PathBuf>, - pub selector: Option<String>, - #[arg(long = "farm-d-tag")] - pub farm_d_tag: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct LookupArgs { - pub key: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct MarketArgs { - #[command(subcommand)] - pub command: MarketCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum MarketCommand { - Refresh, - Product(MarketProductArgs), - Listing(MarketListingArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct MarketProductArgs { - #[command(subcommand)] - pub command: MarketProductCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum MarketProductCommand { - Search(QueryArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct MarketListingArgs { - #[command(subcommand)] - pub command: MarketListingCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum MarketListingCommand { - Get(LookupArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct QueryArgs { - pub query: Vec<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketArgs { - #[command(subcommand)] - pub command: BasketCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum BasketCommand { - Create(BasketCreateArgs), - Get(BasketKeyArgs), - List, - Item(BasketItemArgs), - Adjustment(BasketAdjustmentArgs), - Validate(BasketKeyArgs), - Quote(BasketQuoteArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct BasketCreateArgs { - pub basket_id: Option<String>, - #[arg(long)] - pub listing: Option<String>, - #[arg(long = "listing-addr")] - pub listing_addr: Option<String>, - #[arg(long = "bin-id")] - pub bin_id: Option<String>, - #[arg(long)] - pub quantity: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketKeyArgs { - pub basket_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketItemArgs { - #[command(subcommand)] - pub command: BasketItemCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum BasketItemCommand { - Add(BasketItemMutationArgs), - Update(BasketItemMutationArgs), - Remove(BasketItemRemoveArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct BasketAdjustmentArgs { - #[command(subcommand)] - pub command: BasketAdjustmentCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum BasketAdjustmentCommand { - Add(BasketAdjustmentAddArgs), - Remove(BasketAdjustmentRemoveArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct BasketAdjustmentAddArgs { - pub basket_id: Option<String>, - #[arg(long)] - pub id: Option<String>, - #[arg(long)] - pub effect: Option<String>, - #[arg(long)] - pub amount: Option<String>, - #[arg(long)] - pub currency: Option<String>, - #[arg(long)] - pub reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketAdjustmentRemoveArgs { - pub basket_id: Option<String>, - #[arg(long)] - pub id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketItemMutationArgs { - pub basket_id: Option<String>, - #[arg(long = "item-id")] - pub item_id: Option<String>, - #[arg(long)] - pub listing: Option<String>, - #[arg(long = "listing-addr")] - pub listing_addr: Option<String>, - #[arg(long = "bin-id")] - pub bin_id: Option<String>, - #[arg(long)] - pub quantity: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketItemRemoveArgs { - pub basket_id: Option<String>, - pub item_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct BasketQuoteArgs { - #[command(subcommand)] - pub command: BasketQuoteCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum BasketQuoteCommand { - Create(BasketKeyArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderArgs { - #[command(subcommand)] - pub command: OrderCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderCommand { - Submit(OrderSubmitArgs), - Get(OrderKeyArgs), - List, - App(OrderAppArgs), - Rebind(OrderRebindArgs), - Accept(OrderKeyArgs), - Decline(OrderDeclineArgs), - Cancel(OrderCancelArgs), - Revision(OrderRevisionArgs), - Fulfillment(OrderFulfillmentArgs), - Receipt(OrderReceiptArgs), - Payment(OrderPaymentArgs), - Settlement(OrderSettlementArgs), - Status(OrderStatusArgs), - Event(OrderEventArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderSubmitArgs { - pub order_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderKeyArgs { - pub order_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderAppArgs { - #[command(subcommand)] - pub command: OrderAppCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderAppCommand { - List, - Export(OrderAppExportArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderAppExportArgs { - pub record_id: Option<String>, - #[arg(long)] - pub output: Option<PathBuf>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderRebindArgs { - pub order_id: Option<String>, - pub selector: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderDeclineArgs { - pub order_id: Option<String>, - #[arg(long)] - pub reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderCancelArgs { - pub order_id: Option<String>, - #[arg(long)] - pub reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderRevisionArgs { - #[command(subcommand)] - pub command: OrderRevisionCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderRevisionCommand { - Propose(OrderRevisionProposeArgs), - Accept(OrderRevisionDecisionArgs), - Decline(OrderRevisionDeclineArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderRevisionProposeArgs { - pub order_id: Option<String>, - #[arg(long)] - pub reason: Option<String>, - #[arg(long)] - pub bin_id: Option<String>, - #[arg(long)] - pub bin_count: Option<u32>, - #[arg(long)] - pub adjustment_id: Option<String>, - #[arg(long)] - pub adjustment_effect: Option<String>, - #[arg(long)] - pub adjustment_amount: Option<String>, - #[arg(long)] - pub adjustment_currency: Option<String>, - #[arg(long)] - pub adjustment_reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderRevisionDecisionArgs { - pub order_id: Option<String>, - #[arg(long)] - pub revision_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderRevisionDeclineArgs { - pub order_id: Option<String>, - #[arg(long)] - pub revision_id: Option<String>, - #[arg(long)] - pub reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderFulfillmentArgs { - #[command(subcommand)] - pub command: OrderFulfillmentCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderFulfillmentCommand { - Update(OrderFulfillmentUpdateArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderFulfillmentUpdateArgs { - pub order_id: Option<String>, - #[arg(long, value_enum)] - pub state: Option<OrderFulfillmentStateArg>, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)] -#[value(rename_all = "snake_case")] -pub enum OrderFulfillmentStateArg { - Preparing, - ReadyForPickup, - OutForDelivery, - Delivered, - SellerCancelled, -} - -impl OrderFulfillmentStateArg { - pub const fn as_protocol_state(self) -> &'static str { - match self { - Self::Preparing => "preparing", - Self::ReadyForPickup => "ready_for_pickup", - Self::OutForDelivery => "out_for_delivery", - Self::Delivered => "delivered", - Self::SellerCancelled => "seller_cancelled", - } - } -} - -#[derive(Debug, Clone, Args)] -pub struct OrderReceiptArgs { - #[command(subcommand)] - pub command: OrderReceiptCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderReceiptCommand { - Record(OrderReceiptRecordArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderReceiptRecordArgs { - pub order_id: Option<String>, - #[arg(long, action = ArgAction::SetTrue, conflicts_with = "issue")] - pub received: bool, - #[arg(long)] - pub issue: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderPaymentArgs { - #[command(subcommand)] - pub command: OrderPaymentCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderPaymentCommand { - Record(OrderPaymentRecordArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderPaymentRecordArgs { - pub order_id: Option<String>, - #[arg(long)] - pub amount: Option<String>, - #[arg(long)] - pub currency: Option<String>, - #[arg(long)] - pub method: Option<String>, - #[arg(long)] - pub reference: Option<String>, - #[arg(long)] - pub paid_at: Option<u64>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderSettlementArgs { - #[command(subcommand)] - pub command: OrderSettlementCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderSettlementCommand { - Accept(OrderSettlementAcceptArgs), - Reject(OrderSettlementRejectArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderSettlementAcceptArgs { - pub order_id: Option<String>, - #[arg(long)] - pub payment_event_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderSettlementRejectArgs { - pub order_id: Option<String>, - #[arg(long)] - pub payment_event_id: Option<String>, - #[arg(long)] - pub reason: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct OrderStatusArgs { - #[command(subcommand)] - pub command: OrderStatusCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderStatusCommand { - Get(OrderKeyArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct OrderEventArgs { - #[command(subcommand)] - pub command: OrderEventCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum OrderEventCommand { - List(OrderKeyArgs), - Watch(OrderKeyArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ValidationArgs { - #[command(subcommand)] - pub command: ValidationCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum ValidationCommand { - Receipt(ValidationReceiptArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ValidationReceiptArgs { - #[command(subcommand)] - pub command: ValidationReceiptCommand, -} - -#[derive(Debug, Clone, Subcommand)] -pub enum ValidationReceiptCommand { - Get(ValidationReceiptEventArgs), - List(ValidationReceiptListArgs), - Verify(ValidationReceiptEventArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ValidationReceiptEventArgs { - pub receipt_event_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct ValidationReceiptListArgs { - #[arg(long)] - pub order_id: Option<String>, -} - -#[derive(Debug, Clone, Args)] -pub struct PathOutputArgs { - #[arg(long)] - pub output: Option<PathBuf>, -} - #[cfg(test)] mod tests { use std::collections::BTreeSet; diff --git a/src/cli/order.rs b/src/cli/order.rs @@ -0,0 +1,264 @@ +use std::path::PathBuf; + +use clap::{ArgAction, Args, Subcommand, ValueEnum}; + +#[derive(Debug, Clone, Args)] +pub struct OrderArgs { + #[command(subcommand)] + pub command: OrderCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderCommand { + Submit(OrderSubmitArgs), + Get(OrderKeyArgs), + List, + App(OrderAppArgs), + Rebind(OrderRebindArgs), + Accept(OrderKeyArgs), + Decline(OrderDeclineArgs), + Cancel(OrderCancelArgs), + Revision(OrderRevisionArgs), + Fulfillment(OrderFulfillmentArgs), + Receipt(OrderReceiptArgs), + Payment(OrderPaymentArgs), + Settlement(OrderSettlementArgs), + Status(OrderStatusArgs), + Event(OrderEventArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderSubmitArgs { + pub order_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderKeyArgs { + pub order_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderAppArgs { + #[command(subcommand)] + pub command: OrderAppCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderAppCommand { + List, + Export(OrderAppExportArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderAppExportArgs { + pub record_id: Option<String>, + #[arg(long)] + pub output: Option<PathBuf>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderRebindArgs { + pub order_id: Option<String>, + pub selector: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderDeclineArgs { + pub order_id: Option<String>, + #[arg(long)] + pub reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderCancelArgs { + pub order_id: Option<String>, + #[arg(long)] + pub reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderRevisionArgs { + #[command(subcommand)] + pub command: OrderRevisionCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderRevisionCommand { + Propose(OrderRevisionProposeArgs), + Accept(OrderRevisionDecisionArgs), + Decline(OrderRevisionDeclineArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderRevisionProposeArgs { + pub order_id: Option<String>, + #[arg(long)] + pub reason: Option<String>, + #[arg(long)] + pub bin_id: Option<String>, + #[arg(long)] + pub bin_count: Option<u32>, + #[arg(long)] + pub adjustment_id: Option<String>, + #[arg(long)] + pub adjustment_effect: Option<String>, + #[arg(long)] + pub adjustment_amount: Option<String>, + #[arg(long)] + pub adjustment_currency: Option<String>, + #[arg(long)] + pub adjustment_reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderRevisionDecisionArgs { + pub order_id: Option<String>, + #[arg(long)] + pub revision_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderRevisionDeclineArgs { + pub order_id: Option<String>, + #[arg(long)] + pub revision_id: Option<String>, + #[arg(long)] + pub reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderFulfillmentArgs { + #[command(subcommand)] + pub command: OrderFulfillmentCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderFulfillmentCommand { + Update(OrderFulfillmentUpdateArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderFulfillmentUpdateArgs { + pub order_id: Option<String>, + #[arg(long, value_enum)] + pub state: Option<OrderFulfillmentStateArg>, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)] +#[value(rename_all = "snake_case")] +pub enum OrderFulfillmentStateArg { + Preparing, + ReadyForPickup, + OutForDelivery, + Delivered, + SellerCancelled, +} + +impl OrderFulfillmentStateArg { + pub const fn as_protocol_state(self) -> &'static str { + match self { + Self::Preparing => "preparing", + Self::ReadyForPickup => "ready_for_pickup", + Self::OutForDelivery => "out_for_delivery", + Self::Delivered => "delivered", + Self::SellerCancelled => "seller_cancelled", + } + } +} + +#[derive(Debug, Clone, Args)] +pub struct OrderReceiptArgs { + #[command(subcommand)] + pub command: OrderReceiptCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderReceiptCommand { + Record(OrderReceiptRecordArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderReceiptRecordArgs { + pub order_id: Option<String>, + #[arg(long, action = ArgAction::SetTrue, conflicts_with = "issue")] + pub received: bool, + #[arg(long)] + pub issue: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderPaymentArgs { + #[command(subcommand)] + pub command: OrderPaymentCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderPaymentCommand { + Record(OrderPaymentRecordArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderPaymentRecordArgs { + pub order_id: Option<String>, + #[arg(long)] + pub amount: Option<String>, + #[arg(long)] + pub currency: Option<String>, + #[arg(long)] + pub method: Option<String>, + #[arg(long)] + pub reference: Option<String>, + #[arg(long)] + pub paid_at: Option<u64>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderSettlementArgs { + #[command(subcommand)] + pub command: OrderSettlementCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderSettlementCommand { + Accept(OrderSettlementAcceptArgs), + Reject(OrderSettlementRejectArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderSettlementAcceptArgs { + pub order_id: Option<String>, + #[arg(long)] + pub payment_event_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderSettlementRejectArgs { + pub order_id: Option<String>, + #[arg(long)] + pub payment_event_id: Option<String>, + #[arg(long)] + pub reason: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct OrderStatusArgs { + #[command(subcommand)] + pub command: OrderStatusCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderStatusCommand { + Get(OrderKeyArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct OrderEventArgs { + #[command(subcommand)] + pub command: OrderEventCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum OrderEventCommand { + List(OrderKeyArgs), + Watch(OrderKeyArgs), +} diff --git a/src/cli/relay.rs b/src/cli/relay.rs @@ -0,0 +1,12 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct RelayArgs { + #[command(subcommand)] + pub command: RelayCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum RelayCommand { + List, +} diff --git a/src/cli/signer.rs b/src/cli/signer.rs @@ -0,0 +1,23 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct SignerArgs { + #[command(subcommand)] + pub command: SignerCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum SignerCommand { + Status(SignerStatusArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct SignerStatusArgs { + #[command(subcommand)] + pub command: SignerStatusCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum SignerStatusCommand { + Get, +} diff --git a/src/cli/store.rs b/src/cli/store.rs @@ -0,0 +1,37 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct StoreArgs { + #[command(subcommand)] + pub command: StoreCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum StoreCommand { + Init, + Status(StoreStatusArgs), + Export, + Backup(StoreBackupArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct StoreStatusArgs { + #[command(subcommand)] + pub command: StoreStatusCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum StoreStatusCommand { + Get, +} + +#[derive(Debug, Clone, Args)] +pub struct StoreBackupArgs { + #[command(subcommand)] + pub command: StoreBackupCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum StoreBackupCommand { + Create, +} diff --git a/src/cli/sync.rs b/src/cli/sync.rs @@ -0,0 +1,26 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct SyncArgs { + #[command(subcommand)] + pub command: SyncCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum SyncCommand { + Status(SyncStatusArgs), + Pull, + Push, + Watch, +} + +#[derive(Debug, Clone, Args)] +pub struct SyncStatusArgs { + #[command(subcommand)] + pub command: SyncStatusCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum SyncStatusCommand { + Get, +} diff --git a/src/cli/validation.rs b/src/cli/validation.rs @@ -0,0 +1,44 @@ +use std::path::PathBuf; + +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct ValidationArgs { + #[command(subcommand)] + pub command: ValidationCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum ValidationCommand { + Receipt(ValidationReceiptArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct ValidationReceiptArgs { + #[command(subcommand)] + pub command: ValidationReceiptCommand, +} + +#[derive(Debug, Clone, Subcommand)] +pub enum ValidationReceiptCommand { + Get(ValidationReceiptEventArgs), + List(ValidationReceiptListArgs), + Verify(ValidationReceiptEventArgs), +} + +#[derive(Debug, Clone, Args)] +pub struct ValidationReceiptEventArgs { + pub receipt_event_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct ValidationReceiptListArgs { + #[arg(long)] + pub order_id: Option<String>, +} + +#[derive(Debug, Clone, Args)] +pub struct PathOutputArgs { + #[arg(long)] + pub output: Option<PathBuf>, +} diff --git a/src/cli/workspace.rs b/src/cli/workspace.rs @@ -0,0 +1,13 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Clone, Args)] +pub struct WorkspaceArgs { + #[command(subcommand)] + pub command: WorkspaceCommand, +} + +#[derive(Debug, Clone, Copy, Subcommand)] +pub enum WorkspaceCommand { + Init, + Get, +} diff --git a/src/main.rs b/src/main.rs @@ -24,7 +24,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use clap::Parser; use serde_json::{Value, json}; -use crate::cli::global::{RuntimeInvocationArgs, RuntimeOutputFormatArg}; +use crate::cli::input::runtime_invocation_args_from_target; use crate::cli::{TargetCliArgs, TargetOutputFormat}; use crate::deferred_payment::{deferred_payment_message, is_deferred_payment_operation}; use crate::operation_basket::BasketOperationService; @@ -73,7 +73,7 @@ fn run() -> Result<ExitCode, runtime::RuntimeError> { render_envelope(&envelope, args.format)?; return Ok(envelope_exit_code(&envelope)); } - let config = RuntimeConfig::from_system(&runtime_args_from_target(&args))?; + let config = RuntimeConfig::from_system(&runtime_invocation_args_from_target(&args))?; let logging = initialize_logging(&config.logging)?; let envelope = match validate_request_contract(&request, &config) { Ok(()) => execute_request(request, &config, &logging), @@ -83,40 +83,6 @@ fn run() -> Result<ExitCode, runtime::RuntimeError> { Ok(envelope_exit_code(&envelope)) } -fn runtime_args_from_target(args: &TargetCliArgs) -> RuntimeInvocationArgs { - RuntimeInvocationArgs { - output_format: Some(match args.format { - TargetOutputFormat::Human => RuntimeOutputFormatArg::Human, - TargetOutputFormat::Json => RuntimeOutputFormatArg::Json, - TargetOutputFormat::Ndjson => RuntimeOutputFormatArg::Ndjson, - }), - json: false, - ndjson: false, - env_file: None, - quiet: args.quiet, - verbose: args.verbose, - trace: args.trace, - dry_run: args.dry_run, - no_color: args.no_color, - no_input: args.no_input, - yes: false, - log_filter: None, - log_dir: None, - log_stdout: false, - no_log_stdout: false, - account: args.account_id.clone(), - identity_path: None, - signer: None, - publish_mode: args.publish_mode.map(|mode| mode.as_str().to_owned()), - relay: args.relay.clone(), - myc_executable: None, - myc_status_timeout_ms: None, - hyf_enabled: false, - no_hyf_enabled: false, - hyf_executable: None, - } -} - fn execute_request( request: TargetOperationRequest, config: &RuntimeConfig, diff --git a/src/ops/mod.rs b/src/ops/mod.rs @@ -1122,9 +1122,9 @@ macro_rules! target_operation_contracts { impl TargetOperationRequest { pub fn from_target_args(args: &TargetCliArgs) -> Result<Self, OperationAdapterError> { Self::from_operation_id_with_input( - args.command.operation_id(), + crate::cli::input::operation_id_from_target(args), OperationContext::from_target_args(args), - target_operation_input(&args.command), + crate::cli::input::target_operation_input(&args.command), ) } @@ -1280,336 +1280,6 @@ fn value_to_data(value: Value) -> OperationData { } } -fn target_operation_input(command: &crate::cli::TargetCommand) -> OperationData { - use crate::cli::{ - AccountCommand, AccountSelectionCommand, BasketAdjustmentCommand, BasketCommand, - BasketItemCommand, BasketQuoteCommand, FarmCommand, FarmFulfillmentCommand, - FarmLocationCommand, FarmProfileCommand, ListingAppCommand, ListingCommand, MarketCommand, - MarketListingCommand, MarketProductCommand, OrderAppCommand, OrderCommand, - OrderEventCommand, OrderFulfillmentCommand, OrderPaymentCommand, OrderReceiptCommand, - OrderRevisionCommand, OrderSettlementCommand, OrderStatusCommand, TargetCommand, - ValidationCommand, ValidationReceiptCommand, - }; - - let mut input = OperationData::new(); - match command { - TargetCommand::Account(args) => match &args.command { - AccountCommand::Import(args) => { - insert_path(&mut input, "path", &args.path); - if args.default { - input.insert("default".to_owned(), Value::Bool(true)); - } - } - AccountCommand::AttachSecret(args) => { - insert_string(&mut input, "selector", &args.selector); - insert_path(&mut input, "path", &args.path); - if args.default { - input.insert("default".to_owned(), Value::Bool(true)); - } - } - AccountCommand::Get(args) => insert_string(&mut input, "selector", &args.selector), - AccountCommand::Remove(args) => insert_string(&mut input, "selector", &args.selector), - AccountCommand::Selection(args) => match &args.command { - AccountSelectionCommand::Update(args) => { - insert_string(&mut input, "selector", &args.selector) - } - AccountSelectionCommand::Get | AccountSelectionCommand::Clear => {} - }, - AccountCommand::Create | AccountCommand::List => {} - }, - TargetCommand::Farm(args) => match &args.command { - FarmCommand::Create(args) => { - insert_string(&mut input, "farm_d_tag", &args.farm_d_tag); - insert_string(&mut input, "name", &args.name); - insert_string(&mut input, "display_name", &args.display_name); - insert_string(&mut input, "about", &args.about); - insert_string(&mut input, "website", &args.website); - insert_string(&mut input, "picture", &args.picture); - insert_string(&mut input, "banner", &args.banner); - insert_string(&mut input, "location", &args.location); - insert_string(&mut input, "city", &args.city); - insert_string(&mut input, "region", &args.region); - insert_string(&mut input, "country", &args.country); - insert_string(&mut input, "delivery_method", &args.delivery_method); - } - FarmCommand::Rebind(args) => { - insert_string(&mut input, "selector", &args.selector); - } - FarmCommand::Profile(args) => match &args.command { - FarmProfileCommand::Update(args) => { - insert_string(&mut input, "field", &args.field); - insert_string(&mut input, "value", &args.value); - } - }, - FarmCommand::Location(args) => match &args.command { - FarmLocationCommand::Update(args) => { - insert_string(&mut input, "field", &args.field); - insert_string(&mut input, "value", &args.value); - } - }, - FarmCommand::Fulfillment(args) => match &args.command { - FarmFulfillmentCommand::Update(args) => { - insert_string(&mut input, "value", &args.value); - } - }, - FarmCommand::Get | FarmCommand::Readiness(_) | FarmCommand::Publish => {} - }, - TargetCommand::Listing(args) => match &args.command { - ListingCommand::Create(args) => { - insert_path(&mut input, "output", &args.output); - insert_string(&mut input, "key", &args.key); - insert_string(&mut input, "title", &args.title); - insert_string(&mut input, "category", &args.category); - insert_string(&mut input, "summary", &args.summary); - insert_string(&mut input, "bin_id", &args.bin_id); - insert_string(&mut input, "quantity_amount", &args.quantity_amount); - insert_string(&mut input, "quantity_unit", &args.quantity_unit); - insert_string(&mut input, "price_amount", &args.price_amount); - insert_string(&mut input, "price_currency", &args.price_currency); - insert_string(&mut input, "price_per_amount", &args.price_per_amount); - insert_string(&mut input, "price_per_unit", &args.price_per_unit); - insert_string(&mut input, "available", &args.available); - insert_string(&mut input, "label", &args.label); - insert_string(&mut input, "discount_id", &args.discount_id); - insert_string(&mut input, "discount_label", &args.discount_label); - insert_string(&mut input, "discount_kind", &args.discount_kind); - insert_string(&mut input, "discount_value", &args.discount_value); - insert_string(&mut input, "discount_amount", &args.discount_amount); - insert_string(&mut input, "discount_currency", &args.discount_currency); - } - ListingCommand::Get(args) => insert_string(&mut input, "key", &args.key), - ListingCommand::App(args) => match &args.command { - ListingAppCommand::Export(args) => { - insert_string(&mut input, "record_id", &args.record_id); - insert_path(&mut input, "output", &args.output); - } - ListingAppCommand::List => {} - }, - ListingCommand::Update(args) - | ListingCommand::Validate(args) - | ListingCommand::Publish(args) - | ListingCommand::Archive(args) => insert_path(&mut input, "file", &args.file), - ListingCommand::Rebind(args) => { - insert_path(&mut input, "file", &args.file); - insert_string(&mut input, "selector", &args.selector); - insert_string(&mut input, "farm_d_tag", &args.farm_d_tag); - } - ListingCommand::List => {} - }, - TargetCommand::Market(args) => match &args.command { - MarketCommand::Product(product) => match &product.command { - MarketProductCommand::Search(args) => { - insert_string_array(&mut input, "query", args.query.as_slice()) - } - }, - MarketCommand::Listing(listing) => match &listing.command { - MarketListingCommand::Get(args) => insert_string(&mut input, "key", &args.key), - }, - MarketCommand::Refresh => {} - }, - TargetCommand::Basket(args) => match &args.command { - BasketCommand::Create(args) => { - insert_string(&mut input, "basket_id", &args.basket_id); - insert_string(&mut input, "listing", &args.listing); - insert_string(&mut input, "listing_addr", &args.listing_addr); - insert_string(&mut input, "bin_id", &args.bin_id); - insert_string(&mut input, "quantity", &args.quantity); - } - BasketCommand::Get(args) | BasketCommand::Validate(args) => { - insert_string(&mut input, "basket_id", &args.basket_id) - } - BasketCommand::Item(item) => match &item.command { - BasketItemCommand::Add(args) | BasketItemCommand::Update(args) => { - insert_string(&mut input, "basket_id", &args.basket_id); - insert_string(&mut input, "item_id", &args.item_id); - insert_string(&mut input, "listing", &args.listing); - insert_string(&mut input, "listing_addr", &args.listing_addr); - insert_string(&mut input, "bin_id", &args.bin_id); - insert_string(&mut input, "quantity", &args.quantity); - } - BasketItemCommand::Remove(args) => { - insert_string(&mut input, "basket_id", &args.basket_id); - insert_string(&mut input, "item_id", &args.item_id); - } - }, - BasketCommand::Adjustment(adjustment) => match &adjustment.command { - BasketAdjustmentCommand::Add(args) => { - insert_string(&mut input, "basket_id", &args.basket_id); - insert_string(&mut input, "id", &args.id); - insert_string(&mut input, "effect", &args.effect); - insert_string(&mut input, "amount", &args.amount); - insert_string(&mut input, "currency", &args.currency); - insert_string(&mut input, "reason", &args.reason); - } - BasketAdjustmentCommand::Remove(args) => { - insert_string(&mut input, "basket_id", &args.basket_id); - insert_string(&mut input, "id", &args.id); - } - }, - BasketCommand::Quote(quote) => match &quote.command { - BasketQuoteCommand::Create(args) => { - insert_string(&mut input, "basket_id", &args.basket_id) - } - }, - BasketCommand::List => {} - }, - TargetCommand::Order(args) => match &args.command { - OrderCommand::Submit(args) => { - insert_string(&mut input, "order_id", &args.order_id); - } - OrderCommand::Get(args) => insert_string(&mut input, "order_id", &args.order_id), - OrderCommand::App(args) => match &args.command { - OrderAppCommand::Export(args) => { - insert_string(&mut input, "record_id", &args.record_id); - insert_path(&mut input, "output", &args.output); - } - OrderAppCommand::List => {} - }, - OrderCommand::Rebind(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "selector", &args.selector); - } - OrderCommand::Accept(args) => insert_string(&mut input, "order_id", &args.order_id), - OrderCommand::Decline(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "reason", &args.reason); - } - OrderCommand::Cancel(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "reason", &args.reason); - } - OrderCommand::Revision(revision) => match &revision.command { - OrderRevisionCommand::Propose(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "reason", &args.reason); - insert_string(&mut input, "bin_id", &args.bin_id); - if let Some(bin_count) = args.bin_count { - input.insert( - "bin_count".to_owned(), - Value::Number(serde_json::Number::from(bin_count)), - ); - } - insert_string(&mut input, "adjustment_id", &args.adjustment_id); - insert_string(&mut input, "adjustment_effect", &args.adjustment_effect); - insert_string(&mut input, "adjustment_amount", &args.adjustment_amount); - insert_string(&mut input, "adjustment_currency", &args.adjustment_currency); - insert_string(&mut input, "adjustment_reason", &args.adjustment_reason); - } - OrderRevisionCommand::Accept(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "revision_id", &args.revision_id); - } - OrderRevisionCommand::Decline(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "revision_id", &args.revision_id); - insert_string(&mut input, "reason", &args.reason); - } - }, - OrderCommand::Fulfillment(fulfillment) => match &fulfillment.command { - OrderFulfillmentCommand::Update(args) => { - insert_string(&mut input, "order_id", &args.order_id); - if let Some(state) = args.state { - input.insert( - "state".to_owned(), - Value::String(state.as_protocol_state().to_owned()), - ); - } - } - }, - OrderCommand::Receipt(receipt) => match &receipt.command { - OrderReceiptCommand::Record(args) => { - insert_string(&mut input, "order_id", &args.order_id); - if args.received { - input.insert("received".to_owned(), Value::Bool(true)); - } - insert_string(&mut input, "issue", &args.issue); - } - }, - OrderCommand::Payment(payment) => match &payment.command { - OrderPaymentCommand::Record(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "amount", &args.amount); - insert_string(&mut input, "currency", &args.currency); - insert_string(&mut input, "method", &args.method); - insert_string(&mut input, "reference", &args.reference); - if let Some(paid_at) = args.paid_at { - input.insert( - "paid_at".to_owned(), - Value::Number(serde_json::Number::from(paid_at)), - ); - } - } - }, - OrderCommand::Settlement(settlement) => match &settlement.command { - OrderSettlementCommand::Accept(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "payment_event_id", &args.payment_event_id); - } - OrderSettlementCommand::Reject(args) => { - insert_string(&mut input, "order_id", &args.order_id); - insert_string(&mut input, "payment_event_id", &args.payment_event_id); - insert_string(&mut input, "reason", &args.reason); - } - }, - OrderCommand::Status(status) => match &status.command { - OrderStatusCommand::Get(args) => { - insert_string(&mut input, "order_id", &args.order_id) - } - }, - OrderCommand::Event(event) => match &event.command { - OrderEventCommand::List(args) | OrderEventCommand::Watch(args) => { - insert_string(&mut input, "order_id", &args.order_id) - } - }, - OrderCommand::List => {} - }, - TargetCommand::Validation(args) => match &args.command { - ValidationCommand::Receipt(receipt) => match &receipt.command { - ValidationReceiptCommand::Get(args) | ValidationReceiptCommand::Verify(args) => { - insert_string(&mut input, "receipt_event_id", &args.receipt_event_id); - } - ValidationReceiptCommand::List(args) => { - insert_string(&mut input, "order_id", &args.order_id); - } - }, - }, - _ => {} - } - input -} - -fn insert_string(input: &mut OperationData, key: &str, value: &Option<String>) { - if let Some(value) = value - .as_deref() - .map(str::trim) - .filter(|value| !value.is_empty()) - { - input.insert(key.to_owned(), Value::String(value.to_owned())); - } -} - -fn insert_string_array(input: &mut OperationData, key: &str, values: &[String]) { - let values = values - .iter() - .map(String::as_str) - .map(str::trim) - .filter(|value| !value.is_empty()) - .map(|value| Value::String(value.to_owned())) - .collect::<Vec<_>>(); - if !values.is_empty() { - input.insert(key.to_owned(), Value::Array(values)); - } -} - -fn insert_path(input: &mut OperationData, key: &str, value: &Option<std::path::PathBuf>) { - if let Some(value) = value { - input.insert( - key.to_owned(), - Value::String(value.to_string_lossy().into_owned()), - ); - } -} - target_operation_contracts! { WorkspaceInit => (WorkspaceInitRequest, WorkspaceInitResult, "workspace.init"), WorkspaceGet => (WorkspaceGetRequest, WorkspaceGetResult, "workspace.get"),