From 9647a205022789a8040ba8e44a19f2b10dabab2d Mon Sep 17 00:00:00 2001 From: Yuval Kogman Date: Sun, 21 May 2023 00:07:24 +0300 Subject: [PATCH] carlo: {Build,Upload,Activate}Opt structs --- crates/carlo/src/main.rs | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/crates/carlo/src/main.rs b/crates/carlo/src/main.rs index ed4e577..f8b9d52 100644 --- a/crates/carlo/src/main.rs +++ b/crates/carlo/src/main.rs @@ -5,7 +5,7 @@ use carol::http::api::{BinaryCreated, MachineCreated}; // TODO move to carol_cor use carol::http::server::Encoding; use carol_core::{hex, BinaryId}; use carol_host::Executor; -use clap::{Parser, Subcommand}; +use clap::{Args, Parser, Subcommand}; use std::fmt::Display; use std::process::{Command, Stdio}; use wit_component::ComponentEncoder; @@ -19,17 +19,26 @@ struct Cli { #[derive(Subcommand)] enum Commands { - Build { - crate_dir: Option, - }, - Upload { - carol_url: String, - binary: Utf8PathBuf, - }, - Activate { - carol_url: String, - binary_id: BinaryId, - }, + Build(BuildOpts), + Upload(UploadOpts), + Activate(ActivateOpts), +} + +#[derive(Args)] +struct BuildOpts { + crate_dir: Option, +} + +#[derive(Args)] +struct UploadOpts { + carol_url: String, + binary: Utf8PathBuf, +} + +#[derive(Args)] +struct ActivateOpts { + carol_url: String, + binary_id: BinaryId, } struct Client { @@ -117,7 +126,7 @@ fn main() -> anyhow::Result<()> { let cli = Cli::parse(); let output: Box = match &cli.command { - Commands::Build { crate_dir: dir } => { + Commands::Build(BuildOpts { crate_dir: dir }) => { let mut cmd = Command::new("cargo"); if let Some(dir) = dir { @@ -194,7 +203,7 @@ fn main() -> anyhow::Result<()> { Box::new(component_target) } - Commands::Upload { binary, carol_url } => { + Commands::Upload(UploadOpts { binary, carol_url }) => { let client = Client::new(carol_url.clone()); // Validate and derive BinaryId @@ -210,10 +219,10 @@ fn main() -> anyhow::Result<()> { Box::new(hex::encode(response_binary_id.as_ref())) } - Commands::Activate { + Commands::Activate(ActivateOpts { binary_id, carol_url, - } => { + }) => { let client = Client::new(carol_url.clone()); let machine_id = client.activate(binary_id)?.id;