tftio-asana-cli 3.1.0

An interface to the Asana API
Documentation
//! Output helpers for rendering command results.

pub mod project;
pub mod task;

use clap::ValueEnum;
use std::fmt;
use std::str::FromStr;

/// Unified output format used by every asana-cli command.
///
/// `Table` adapts to single-record (vertical key/value) vs collection (horizontal
/// rows) at the renderer layer.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
    /// Human-readable table; renders vertically for single records.
    #[default]
    Table,
    /// JSON representation suitable for scripting.
    Json,
    /// Comma separated value export.
    Csv,
    /// Markdown friendly tables.
    Markdown,
}

impl fmt::Display for OutputFormat {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Self::Table => "table",
            Self::Json => "json",
            Self::Csv => "csv",
            Self::Markdown => "markdown",
        })
    }
}

impl FromStr for OutputFormat {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_ascii_lowercase().as_str() {
            "table" => Ok(Self::Table),
            "json" => Ok(Self::Json),
            "csv" => Ok(Self::Csv),
            "markdown" | "md" => Ok(Self::Markdown),
            other => Err(format!(
                "unsupported output format '{other}'; expected table, json, csv, or markdown"
            )),
        }
    }
}

/// Backwards-compatible alias retained while task/project output modules transition.
pub type TaskOutputFormat = OutputFormat;
/// Backwards-compatible alias retained while task/project output modules transition.
pub type ProjectOutputFormat = OutputFormat;