cirious_codex_derive 0.2.0

Centralized Procedural Macros for the Cirious Codex Ecosystem
Documentation
//! Cirious Codex Example Module.
//!
//! This module demonstrates the usage of the Cirious Codex ecosystem,
//! showcasing the implementation of CLI commands and subcommands using
//! procedural macros.
//!
use cirious_codex_derive::{CodexCommand, CodexParser, CodexSubcommand};

/// Global arguments shared across all CLI commands.
#[derive(Debug, Clone)]
pub struct GlobalArgs {
  /// Enables verbose mode for detailed diagnostic logging.
  pub verbose: bool,
  /// Optional path to a configuration file.
  pub config_path: Option<String>,
}

/// A trait defining the contract for any command that utilizes global arguments.
pub trait CodexCommand {
  /// Returns a reference to the global arguments.
  fn global_args(&self) -> &GlobalArgs;
}

/// Arguments specific to the build command.
#[derive(CodexParser, CodexCommand, Debug)]
pub struct BuildArgs {
  /// Global arguments injected by the `CodexCommand` macro.
  pub global: GlobalArgs,
  /// Example argument for the build process.
  #[codex(aliase = "", command = "build-example", default_value = "app-example")]
  pub build_example: String,
}

/// Arguments specific to the run command.
#[derive(CodexParser, CodexCommand, Debug)]
pub struct RunArgs {
  /// Global arguments injected by the `CodexCommand` macro.
  pub global: GlobalArgs,
  /// Example argument for the execution process.
  #[codex(aliase = "", command = "run-example", default_value = "app-example")]
  pub run_example: String,
}

/// The central subcommand router for the CLI application.
#[derive(CodexSubcommand)]
enum MyCLI {
  /// Build command variant.
  Build(BuildArgs),
  /// Run command variant.
  Run(RunArgs),
}

fn main() {
  let command = MyCLI::parse();
  match command {
    MyCLI::Build(args) => println!("Construindo com {args:?}"),
    MyCLI::Run(args) => println!("Executando com {args:?}"),
  }
}