1pub mod add;
2pub mod categories;
3pub mod completion;
4pub mod gen;
5pub mod github;
6pub mod graph;
7pub mod hazard;
8pub mod lint;
9pub mod list;
10pub mod packs;
11pub mod remove;
12pub mod search;
13pub mod show;
14pub mod update;
15
16use clap::Subcommand;
17use ggen_utils::UtilsGgenConfig as GgenConfig;
18
19#[derive(Subcommand, Debug)]
20pub enum Commands {
21 #[command(name = "search", about = "Search for rpacks in registry")]
22 Search(search::SearchArgs),
23 #[command(name = "categories", about = "Show popular categories and keywords")]
24 Categories(categories::CategoriesArgs),
25 #[command(name = "add", about = "Add an rpack to the project")]
26 Add(add::AddArgs),
27 #[command(name = "remove", about = "Remove an rpack from the project")]
28 Remove(remove::RemoveArgs),
29 #[command(name = "packs", about = "List installed rpacks")]
30 Packs,
31 #[command(name = "update", about = "Update rpacks to latest compatible versions")]
32 Update(update::UpdateArgs),
33 #[command(name = "gen", about = "Generate code from templates")]
34 Gen(gen::GenArgs),
35 #[command(name = "list", about = "List available templates")]
36 List,
37 #[command(name = "show", about = "Show template metadata")]
38 Show(show::ShowArgs),
39 #[command(name = "validate", about = "Validate template frontmatter")]
40 #[command(name = "lint", about = "Lint template with schema validation")]
41 Lint(lint::LintArgs),
42 #[command(name = "graph", about = "Export RDF graph")]
43 Graph(graph::GraphArgs),
44 #[command(name = "github", about = "GitHub API operations (Pages, workflows)")]
45 GitHub(github::GitHubArgs),
46 #[command(name = "hazard", about = "Generate hazard report")]
47 Hazard,
48 #[command(name = "completion", about = "Generate completion scripts")]
49 Completion {
50 #[command(subcommand)]
51 subcommand: CompletionSubcommand,
52 },
53}
54
55#[derive(Subcommand, PartialEq, Debug)]
56pub enum CompletionSubcommand {
57 #[command(about = "generate the autocompletion script for bash")]
58 Bash,
59 #[command(about = "generate the autocompletion script for zsh")]
60 Zsh,
61 #[command(about = "generate the autocompletion script for fish")]
62 Fish,
63}
64
65impl Commands {
66 pub async fn run(&self) -> ggen_utils::error::Result<()> {
67 match self {
68 Commands::Search(args) => Ok(search::run(args).await?),
69 Commands::Categories(args) => Ok(categories::run(args).await?),
70 Commands::Add(args) => Ok(add::run(args).await?),
71 Commands::Remove(args) => Ok(remove::run(args)?),
72 Commands::Packs => Ok(packs::run()?),
73 Commands::Update(args) => Ok(update::run(args).await?),
74 Commands::Gen(args) => Ok(gen::run(args)?),
75 Commands::List => list::run(),
76 Commands::Show(args) => show::run(args),
77 Commands::Lint(args) => lint::run(args),
78 Commands::Graph(args) => graph::run(args),
79 Commands::GitHub(args) => Ok(github::run(args).await?),
80 Commands::Hazard => hazard::run(),
81 Commands::Completion { subcommand } => completion::run(subcommand),
82 }
83 }
84
85 pub async fn run_with_config(
86 &self, _ggen_config: Option<GgenConfig>,
87 ) -> ggen_utils::error::Result<()> {
88 match self {
89 Commands::Search(args) => Ok(search::run(args).await?),
90 Commands::Categories(args) => Ok(categories::run(args).await?),
91 Commands::Add(args) => Ok(add::run(args).await?),
92 Commands::Remove(args) => Ok(remove::run(args)?),
93 Commands::Packs => Ok(packs::run()?),
94 Commands::Update(args) => Ok(update::run(args).await?),
95 Commands::Gen(args) => Ok(gen::run(args)?),
96 Commands::List => list::run(),
97 Commands::Show(args) => show::run(args),
98 Commands::Lint(args) => lint::run(args),
99 Commands::Graph(args) => graph::run(args),
100 Commands::GitHub(args) => Ok(github::run(args).await?),
101 Commands::Hazard => hazard::run(),
102 Commands::Completion { subcommand } => completion::run(subcommand),
103 }
104 }
105}