nestrs-cli-rs 0.1.0

Rust port of the Nest CLI for the nestrs organization.
Documentation
//! Upstream source: `../nest-cli/commands/command.loader.ts`.

use crate::actions::ActionInvocation;

use super::{CommandSpec, command_specs};

/// Typed Rust equivalent of upstream `CommandLoader`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct CommandLoader;

pub use super::{CommandParseError, load_command_invocation};

impl CommandLoader {
    pub const fn new() -> Self {
        Self
    }

    pub fn specs(&self) -> &'static [CommandSpec] {
        command_specs()
    }

    pub fn load<I, S>(&self, args: I) -> Result<ActionInvocation, CommandParseError>
    where
        I: IntoIterator<Item = S>,
        S: AsRef<str>,
    {
        load_command_invocation(args)
    }

    pub fn invalid_command_message(command: &str) -> String {
        format!(
            "\nError  Invalid command: {command}\nSee --help for a list of available commands.\n"
        )
    }
}