Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions src/cmd_api_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ pub struct CmdApiCallStatus {
#[async_trait::async_trait(?Send)]
impl crate::cmd::Command for CmdApiCallStatus {
async fn run(&self, ctx: &mut crate::context::Context) -> Result<()> {
let format = ctx.format(&self.format)?;
let client = ctx.api_client("")?;

let api_call = client.api_calls().get_async_operation(self.id).await?;
let mut api_call = client.api_calls().get_async_operation(self.id).await?;

// If it is a file conversion and there is output, we need to save that output to a file
// for them.
Expand All @@ -66,12 +67,12 @@ impl crate::cmd::Command for CmdApiCallStatus {
status,
updated_at: _,
user_id: _,
} = &api_call
} = &mut api_call
&& *status == kittycad::types::ApiCallStatus::Completed
&& let Some(outputs) = &outputs
&& let Some(files) = outputs
{
let path = std::env::current_dir()?;
for (name, output) in outputs {
for (name, output) in files.iter() {
if output.is_empty() {
anyhow::bail!(
"no output was generated for the file conversion! (this is probably a bug in the API) you should report it to support@zoo.dev"
Expand All @@ -81,22 +82,46 @@ impl crate::cmd::Command for CmdApiCallStatus {
std::fs::write(&path, &output.0)?;
}

let paths = outputs
let paths = files
.keys()
.map(|k| path.join(k))
.map(|p| p.to_string_lossy().to_string())
.collect_vec();
// Tell them where we saved the file.
writeln!(ctx.io.out, "Saved file conversion output(s) to: {}", paths.join(", "))?;
ctx.io.write_status(
&format,
format_args!("Saved file conversion output(s) to: {}", paths.join(", ")),
)?;

// Return early.
return Ok(());
// The files are on disk; avoid printing their base64 contents as well.
*outputs = None;
}

// Print the output of the conversion.
// TODO: make this work as a table.
ctx.io.write_output(&crate::types::FormatOutput::Json, &api_call)?;
match format {
crate::types::FormatOutput::Json => ctx.io.write_output_json(&serde_json::to_value(&api_call)?)?,
crate::types::FormatOutput::Yaml => ctx.io.write_output_yaml(&api_call)?,
crate::types::FormatOutput::Table => {
let serde_json::Value::Object(fields) = serde_json::to_value(&api_call)? else {
anyhow::bail!("Expected an object for the API call status");
};
ctx.io
.write_output_table_for_vec(fields.into_iter().map(|(property, value)| ApiCallStatusRow {
property,
value: match value {
serde_json::Value::String(value) => value,
value => value.to_string(),
},
}))?;
}
}

Ok(())
}
}

#[derive(tabled::Tabled)]
#[tabled(rename_all = "PascalCase")]
struct ApiCallStatusRow {
property: String,
value: String,
}
31 changes: 13 additions & 18 deletions src/cmd_kcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ pub struct CmdKclExport {
#[clap(short = 't', long = "output-format", value_enum)]
output_format: kittycad::types::FileExportFormat,

/// Command output format.
#[clap(long, short, value_enum)]
pub format: Option<FormatOutput>,

/// If true, print a link to this request's tracing data.
#[clap(long, default_value = "false")]
pub show_trace: bool,
Expand Down Expand Up @@ -323,13 +319,10 @@ pub struct CmdKclSnapshot {
#[clap(short = 't', long = "output-format", value_enum)]
output_format: Option<kittycad::types::ImageFormat>,

/// Command output format.
#[clap(long, short, value_enum)]
pub format: Option<FormatOutput>,

/// If given, this command will reuse an existing KittyCAD modeling session.
/// You can start the session via `zoo session-start --listen-on 0.0.0.0:3333` in this CLI.
#[clap(long, default_value = None)]
/// You can start the session via `zoo start-session 0.0.0.0:3333` in this CLI.
/// Sessions return PNG using the server's fixed rendering settings.
#[clap(long, conflicts_with_all = ["angle", "camera_style", "camera_padding", "replay", "allow_errors", "show_trace"])]
pub session: Option<SocketAddr>,

/// If true, print a link to this request's tracing data.
Expand Down Expand Up @@ -384,6 +377,12 @@ impl crate::cmd::Command for CmdKclSnapshot {
get_image_format_from_extension_kcmc(&crate::cmd_file::get_extension(self.output_file.clone()))?
};

if self.session.is_some() && output_format != kcmc::ImageFormat::Png {
anyhow::bail!(
"--session only supports PNG snapshots; use --output-format png or omit --session for other formats"
);
}

// Get the contents of the input file.
let (code, filepath) = ctx.get_code_and_file_path(&self.input).await?;

Expand All @@ -395,7 +394,6 @@ impl crate::cmd::Command for CmdKclSnapshot {

let (many_pngs, session_data) = match self.session {
Some(addr) => {
// TODO
let client = reqwest::ClientBuilder::new().build()?;
let url = Url::parse(&format!("http://{addr}"))?;
let resp = client
Expand Down Expand Up @@ -602,10 +600,6 @@ pub struct CmdKclView {
#[clap(name = "input", required = true)]
pub input: std::path::PathBuf,

/// Command output format.
#[clap(long, short, value_enum)]
pub format: Option<FormatOutput>,

/// Which angle to take the snapshot from.
/// Defaults to "front".
#[clap(long, value_enum)]
Expand Down Expand Up @@ -1248,6 +1242,8 @@ impl crate::cmd::Command for CmdKclVolume {
#[async_trait::async_trait(?Send)]
impl crate::cmd::Command for CmdKclBoundingBox {
async fn run(&self, ctx: &mut crate::context::Context) -> Result<()> {
let format = ctx.format(&self.format)?;

// Get the contents of the input file.
let (code, filepath) = ctx.get_code_and_file_path(&self.input).await?;

Expand Down Expand Up @@ -1276,9 +1272,8 @@ impl crate::cmd::Command for CmdKclBoundingBox {
} = &resp
{
// Print the output.
let output_unit = self.output_unit;
let printable_box = bounding_box_rows(data, output_unit);
ctx.io.write_output_table_for_vec(&printable_box)?;
let printable_box = bounding_box_rows(data, self.output_unit);
ctx.io.write_output_for_vec(&format, printable_box)?;
} else {
anyhow::bail!("Unexpected response from engine: {resp:?}");
}
Expand Down
Loading
Loading