cirious_codex_derive 0.2.0

Centralized Procedural Macros for the Cirious Codex Ecosystem
Documentation
//! Example demonstrating the usage of the `CodexParser` derive macro.
//!
//! To run this example, ensure the workspace is correctly configured.

use cirious_codex_derive::{CodexCommand, CodexParser};

/// 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;
}

/// Example demonstrating the usage of the `CodexParser` derive macro.
#[derive(CodexParser, CodexCommand, Debug)]
pub struct AuthConfig {
  /// Global arguments shared across the CLI.
  pub global: GlobalArgs,

  /// The port to bind the server.
  #[codex(aliase = "p", command = "port", default_value = "3000")]
  pub port: u16,

  /// The path to the configuration file.
  #[codex(
    aliase = "c",
    command = "config",
    default_value = "examples/resources/config/test.json"
  )]
  pub config_path: String,
}

fn main() {
  // If parse_cli returns AuthConfig directly, just assign it
  let config = AuthConfig::parse_cli(None);

  println!("Server will bind to port: {}", config.port);
  println!("Config file location: {}", config.config_path);

  if config.global.verbose {
    println!("Verbose mode is ON");
  }
}