CliCommand

Trait CliCommand 

Source
pub trait CliCommand {
    // Required methods
    fn process(&self, req: &CliRequest) -> Result<()>;
    fn help(&self) -> CliHelpScreen;
}
Expand description

Trait that all CLI commands must implement.

This trait defines the interface for CLI commands, requiring implementations to provide both a process method for executing the command and a help method for generating help documentation.

§Example

use falcon_cli::{CliCommand, CliRequest, CliHelpScreen};

struct MyCommand;

impl CliCommand for MyCommand {
    fn process(&self, req: &CliRequest) -> anyhow::Result<()> {
        println!("Executing command");
        Ok(())
    }

    fn help(&self) -> CliHelpScreen {
        CliHelpScreen::new("My Command", "myapp mycommand", "Does something useful")
    }
}

Required Methods§

Source

fn process(&self, req: &CliRequest) -> Result<()>

Processes the CLI command with the given request.

§Arguments
  • req - The CLI request containing arguments, flags, and other parsed data
§Returns

Returns Ok(()) on success or an error on failure.

Source

fn help(&self) -> CliHelpScreen

Returns the help screen for this command.

This method should create and return a CliHelpScreen with information about how to use the command, including parameters, flags, and examples.

Implementors§