Skip to main content

cli/commands/
command_loader.rs

1//! Upstream source: `../nest-cli/commands/command.loader.ts`.
2
3use crate::actions::ActionInvocation;
4
5use super::{CommandSpec, command_specs};
6
7/// Typed Rust equivalent of upstream `CommandLoader`.
8#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
9pub struct CommandLoader;
10
11pub use super::{CommandParseError, load_command_invocation};
12
13impl CommandLoader {
14    pub const fn new() -> Self {
15        Self
16    }
17
18    pub fn specs(&self) -> &'static [CommandSpec] {
19        command_specs()
20    }
21
22    pub fn load<I, S>(&self, args: I) -> Result<ActionInvocation, CommandParseError>
23    where
24        I: IntoIterator<Item = S>,
25        S: AsRef<str>,
26    {
27        load_command_invocation(args)
28    }
29
30    pub fn invalid_command_message(command: &str) -> String {
31        format!(
32            "\nError  Invalid command: {command}\nSee --help for a list of available commands.\n"
33        )
34    }
35}