Skip to main content

gen_circleci_orb/
lib.rs

1//! # gen-circleci-orb
2//!
3//! Generate a CircleCI orb from a CLI program definition.
4
5use anyhow::Result;
6use clap::Parser;
7
8pub mod ci_patcher;
9pub mod commands;
10pub mod help_parser;
11pub mod orb_config;
12pub mod orb_generator;
13pub mod output_writer;
14
15/// Command-line interface for gen-circleci-orb.
16#[derive(Debug, Parser)]
17#[command(author, version, about, long_about = None)]
18pub struct Cli {
19    #[command(subcommand)]
20    pub command: Commands,
21}
22
23/// Available subcommands.
24#[derive(Debug, clap::Subcommand)]
25pub enum Commands {
26    /// Manage the gen-circleci-orb.toml configuration file.
27    Config(commands::config::Config),
28    /// Ensure a CircleCI orb is registered, creating it if it does not exist.
29    EnsureOrbRegistered(commands::ensure_orb_registered::EnsureOrbRegistered),
30    /// Generate orb source files from a CLI binary's --help output.
31    Generate(Box<commands::generate::Generate>),
32    /// Wire orb generation into an existing repo's CI configuration.
33    Init(Box<commands::init::Init>),
34    /// Re-sync an existing repo's orb-managed CI wiring to the current flow.
35    Update(commands::update::Update),
36}
37
38impl Cli {
39    /// Execute the selected command.
40    pub fn run(&self) -> Result<()> {
41        match &self.command {
42            Commands::Config(cmd) => cmd.run(),
43            Commands::EnsureOrbRegistered(cmd) => cmd.run(),
44            Commands::Generate(cmd) => cmd.run(),
45            Commands::Init(cmd) => cmd.run(),
46            Commands::Update(cmd) => cmd.run(),
47        }
48    }
49}