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