soroban-cli 27.1.0

Soroban CLI
Documentation
use crate::commands::{container::shared::Error as ConnectionError, global};
use crate::print;

use super::shared::{Args, Name};

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error(transparent)]
    Docker(#[from] ConnectionError),

    #[error("failed to tail container logs")]
    TailContainerError,
}

#[derive(Debug, clap::Parser, Clone)]
pub struct Cmd {
    #[command(flatten)]
    pub container_args: Args,

    /// Container to get logs from
    #[arg(default_value = "local")]
    pub name: String,
}

impl Cmd {
    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
        let print = print::Print::new(global_args.quiet);
        let container_name = Name(self.name.clone()).get_internal_container_name();

        self.container_args.warn_if_host_ignored(&print);

        // Stream logs straight to the terminal by inheriting stdio.
        let status = self
            .container_args
            .logs_command(&container_name)
            .status()
            .await
            .map_err(|e| self.container_args.io_error(e))?;

        if !status.success() {
            return Err(Error::TailContainerError);
        }

        Ok(())
    }
}