ggen-cli-lib 26.7.3

CLI interface for ggen
Documentation
{#- Legacy command module template (backward compat)
    Generates a single #[noun] + #[verb] module pair.
    Delegates to crate::domain::<module> — no domain logic here.

    Expected variables:
    - command_name: string
    - about: string
    - arguments: array of { name, type, comment, required }
    - flags: array of { name, short_flag, comment }
-#}
//! CLI layer for {{ command_name }}
//!
//! This module contains ONLY argument parsing and routing.
//! Domain logic lives in crate::domain::{{ command_name | snake }}.

use clap_noun_verb::Result;
use clap_noun_verb_macros::{noun, verb};

#[noun("{{ command_name }}", "{{ about | default(value='') }}")]
mod {{ command_name | snake }} {
    use super::*;

    {%- if arguments | length > 0 or flags | length > 0 %}

    /// Execute {{ command_name }}
    #[verb("run")]
    pub fn run({% for a in arguments %}{%- if a.required %}{{ a.name }}: {{ a.type }}{% else %}{{ a.name }}: Option<{{ a.type }}>{% endif %}{%- if not loop.last or flags | length > 0 %}, {% endif %}{% endfor %}{% for f in flags %}{{ f.name }}: bool{%- if not loop.last %}, {% endif %}{% endfor %}) -> Result<serde_json::Value> {
        let result = crate::domain::{{ command_name | snake }}::run(
            {%- for a in arguments %}
            {{ a.name }},
            {%- endfor %}
            {%- for f in flags %}
            {{ f.name }},
            {%- endfor %}
        ).map_err(|e| crate::error::CliError::from(e))?;
        Ok(serde_json::to_value(&result).map_err(|e| crate::error::CliError::Serialization(e.to_string()))?)
    }
    {%- else %}

    /// Execute {{ command_name }}
    #[verb("run")]
    pub fn run() -> Result<serde_json::Value> {
        let result = crate::domain::{{ command_name | snake }}::run()
            .map_err(|e| crate::error::CliError::from(e))?;
        Ok(serde_json::to_value(&result).map_err(|e| crate::error::CliError::Serialization(e.to_string()))?)
    }
    {%- endif %}
}