1#[cfg(not(target_os = "emscripten"))]
2mod cmd_auth;
3mod cmd_cache;
4mod cmd_derive;
5mod cmd_export;
6mod cmd_haiku;
7mod cmd_import;
8mod cmd_incept;
9mod cmd_list;
10mod cmd_merge;
11#[cfg(not(target_os = "emscripten"))]
12mod cmd_pathbase;
13mod cmd_project;
14mod cmd_query;
15mod cmd_render;
16#[cfg(not(target_os = "emscripten"))]
17mod cmd_show;
18mod cmd_track;
19mod cmd_validate;
20mod config;
21#[cfg(not(target_os = "emscripten"))]
22mod fzf;
23mod io;
24
25use anyhow::Result;
26use clap::{Parser, Subcommand};
27use std::path::PathBuf;
28
29#[derive(Parser, Debug)]
30#[command(name = "path", version)]
31#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
32struct Cli {
33 #[command(subcommand)]
34 command: Commands,
35
36 #[arg(long, global = true)]
38 pretty: bool,
39}
40
41#[derive(Subcommand, Debug)]
42enum Commands {
43 List {
45 #[command(subcommand)]
46 source: cmd_list::ListSource,
47
48 #[arg(long, global = true, value_enum)]
50 format: Option<cmd_list::ListFormat>,
51
52 #[arg(long, global = true)]
54 json: bool,
55 },
56 Import {
58 #[command(flatten)]
59 args: cmd_import::ImportArgs,
60 },
61 Export {
63 #[command(subcommand)]
64 target: cmd_export::ExportTarget,
65 },
66 Cache {
68 #[command(subcommand)]
69 op: cmd_cache::CacheOp,
70 },
71 Query {
73 #[command(subcommand)]
74 op: cmd_query::QueryOp,
75 },
76 Render {
78 #[command(subcommand)]
79 format: cmd_render::RenderFormat,
80 },
81 #[cfg(not(target_os = "emscripten"))]
83 Show {
84 #[command(subcommand)]
85 source: cmd_show::ShowSource,
86 },
87 Merge {
89 #[arg(required = true)]
91 inputs: Vec<String>,
92
93 #[arg(long)]
95 title: Option<String>,
96 },
97 Track {
99 #[command(subcommand)]
100 op: cmd_track::TrackOp,
101 },
102 Validate {
104 #[arg(short, long)]
106 input: PathBuf,
107 },
108 Haiku,
110 #[cfg(not(target_os = "emscripten"))]
112 Auth {
113 #[command(subcommand)]
114 op: cmd_auth::AuthOp,
115 },
116
117 #[command(hide = true, about = "[deprecated] Use `path import`")]
119 Derive {
120 #[command(subcommand)]
121 source: cmd_derive::DeriveSource,
122 },
123 #[command(hide = true, about = "[deprecated] Use `path export claude`")]
124 Incept {
125 #[command(flatten)]
126 args: cmd_incept::InceptArgs,
127 },
128 #[command(hide = true, about = "[deprecated] Use `path export`")]
129 Project {
130 #[command(subcommand)]
131 target: cmd_project::ProjectTarget,
132 },
133}
134
135pub fn run() -> Result<()> {
136 let cli = Cli::parse();
137
138 match cli.command {
139 Commands::List {
140 source,
141 format,
142 json,
143 } => cmd_list::run(source, format, json),
144 Commands::Import { args } => cmd_import::run(args, cli.pretty),
145 Commands::Export { target } => cmd_export::run(target),
146 Commands::Cache { op } => cmd_cache::run(op),
147 Commands::Query { op } => cmd_query::run(op, cli.pretty),
148 Commands::Render { format } => cmd_render::run(format),
149 #[cfg(not(target_os = "emscripten"))]
150 Commands::Show { source } => cmd_show::run(source),
151 Commands::Merge { inputs, title } => cmd_merge::run(inputs, title, cli.pretty),
152 Commands::Track { op } => cmd_track::run(op, cli.pretty),
153 Commands::Validate { input } => cmd_validate::run(input),
154 Commands::Haiku => {
155 cmd_haiku::run();
156 Ok(())
157 }
158 #[cfg(not(target_os = "emscripten"))]
159 Commands::Auth { op } => cmd_auth::run(op),
160
161 Commands::Derive { source } => cmd_derive::run(source, cli.pretty),
162 Commands::Incept { args } => cmd_incept::run(args),
163 Commands::Project { target } => cmd_project::run(target),
164 }
165}