|
1 | 1 | use { |
2 | 2 | crate::Cli, |
3 | | - anstream::{eprintln, println}, |
4 | | - crossterm::style::Stylize as _, |
5 | 3 | futures::{FutureExt as _, TryStreamExt as _}, |
6 | | - std::path::PathBuf, |
| 4 | + std::{fmt::Write as _, path::PathBuf}, |
7 | 5 | tangram_client::{self as tg, prelude::*}, |
8 | 6 | tangram_futures::task::Task, |
9 | 7 | }; |
@@ -40,17 +38,8 @@ pub struct Options { |
40 | 38 | #[arg(long, short)] |
41 | 39 | pub detach: bool, |
42 | 40 |
|
43 | | - /// Whether to print blobs. |
44 | | - #[arg(long)] |
45 | | - pub print_blobs: bool, |
46 | | - |
47 | | - /// The depth with which to print the output. |
48 | | - #[arg(default_value = "0", long)] |
49 | | - pub print_depth: crate::object::get::Depth, |
50 | | - |
51 | | - /// Whether to pretty print the output. |
52 | | - #[arg(long)] |
53 | | - pub print_pretty: Option<bool>, |
| 41 | + #[command(flatten)] |
| 42 | + pub print: crate::print::ValueOptions, |
54 | 43 |
|
55 | 44 | #[command(flatten)] |
56 | 45 | pub spawn: crate::process::spawn::Options, |
@@ -93,17 +82,21 @@ impl Cli { |
93 | 82 |
|
94 | 83 | // If the detach flag is set, then print the process ID and return. |
95 | 84 | if options.detach { |
96 | | - Self::print_json(&output, None).await?; |
| 85 | + let options = crate::print::Options { |
| 86 | + json: options.print.json, |
| 87 | + pretty: options.print.pretty, |
| 88 | + }; |
| 89 | + Self::print_one(output, options).await?; |
97 | 90 | return Ok(()); |
98 | 91 | } |
99 | 92 |
|
100 | 93 | // Print the process. |
101 | 94 | if !self.args.quiet { |
102 | | - eprint!("{} {}", "info".blue().bold(), process.item().id()); |
| 95 | + let mut message = process.item().id().to_string(); |
103 | 96 | if let Some(token) = process.item().token() { |
104 | | - eprint!(" {token}"); |
| 97 | + write!(message, " {token}").unwrap(); |
105 | 98 | } |
106 | | - eprintln!(); |
| 99 | + Self::print_info_message(&message); |
107 | 100 | } |
108 | 101 |
|
109 | 102 | // Get the process's status. |
@@ -265,21 +258,18 @@ impl Cli { |
265 | 258 | .map_err(|source| tg::error!(!source, "failed to check out the artifact"))?; |
266 | 259 |
|
267 | 260 | // Print the path. |
268 | | - println!("{}", path.display()); |
| 261 | + let options = crate::print::Options { |
| 262 | + json: options.print.json, |
| 263 | + pretty: options.print.pretty, |
| 264 | + }; |
| 265 | + Self::print_one(path, options).await?; |
269 | 266 |
|
270 | 267 | return Ok(()); |
271 | 268 | } |
272 | 269 |
|
273 | 270 | // Print the output. |
274 | 271 | if !output.is_null() { |
275 | | - Self::print_value( |
276 | | - &handle, |
277 | | - &output, |
278 | | - options.print_depth, |
279 | | - options.print_pretty, |
280 | | - options.print_blobs, |
281 | | - ) |
282 | | - .await?; |
| 272 | + Self::print_value(&handle, &output, options.print).await?; |
283 | 273 | } |
284 | 274 |
|
285 | 275 | Ok(()) |
|
0 commit comments