1#[cfg(feature = "admin")]
2mod admin;
3mod args;
4mod client;
5mod command;
6mod confirm;
7mod error;
8mod runs;
9mod triggers;
10mod ui;
11mod whoami;
12
13use anyhow::Result;
14pub use command::Command;
15pub(crate) use confirm::confirm_or_abort;
16use tokio::io::AsyncWriteExt;
17use tracing::log::info;
18
19pub use self::args::Cli;
20
21pub async fn run_cli(args: Cli) -> Result<()> {
22 info!("Base url: {}", args.common.base_url());
23 let stdout = tokio::io::stdout();
24 let mut stdout = tokio::io::BufWriter::new(stdout);
25
26 let stderr = tokio::io::stderr();
27 let mut stderr = tokio::io::BufWriter::new(stderr);
28 let res = args
29 .command
30 .run(&mut stdout, &mut stderr, &args.common)
31 .await;
32 stdout.flush().await?;
33 stderr.flush().await?;
34 res
35}
36
37macro_rules! emitln {
38 ($dst: expr) => {
39 {
40 tokio::io::AsyncWriteExt::write_all($dst, b"\n").await?
41 }
42 };
43 ($dst: expr, $fmt: expr) => {
44 {
45 use std::io::Write;
46 let mut buf = Vec::<u8>::new();
47 writeln!(buf, $fmt)?;
48 tokio::io::AsyncWriteExt::write_all($dst, &buf).await?
49 }
50 };
51 ($dst: expr, $fmt: expr, $($arg: tt)*) => {
52 {
53 use std::io::Write;
54 let mut buf = Vec::<u8>::new();
55 writeln!(buf, $fmt, $( $arg )*)?;
56 tokio::io::AsyncWriteExt::write_all($dst, &buf).await?
57 }
58 };
59}
60
61pub(crate) use emitln;