Skip to content

Commit

Permalink
carlo: {Build,Upload,Activate}Opt structs
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingmuch committed May 26, 2023
1 parent 740fa93 commit 9647a20
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions crates/carlo/src/main.rs
Expand Up @@ -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;
Expand All @@ -19,17 +19,26 @@ struct Cli {

#[derive(Subcommand)]
enum Commands {
Build {
crate_dir: Option<Utf8PathBuf>,
},
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<Utf8PathBuf>,
}

#[derive(Args)]
struct UploadOpts {
carol_url: String,
binary: Utf8PathBuf,
}

#[derive(Args)]
struct ActivateOpts {
carol_url: String,
binary_id: BinaryId,
}

struct Client {
Expand Down Expand Up @@ -117,7 +126,7 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

let output: Box<dyn Display> = 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 {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 9647a20

Please sign in to comment.