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_kind;
10mod cmd_list;
11mod cmd_merge;
12mod cmd_p;
13mod cmd_p_query;
14#[cfg(not(target_os = "emscripten"))]
15mod cmd_pathbase;
16mod cmd_project;
17mod cmd_query;
18mod cmd_render;
19#[cfg(not(target_os = "emscripten"))]
20pub mod cmd_resume;
21#[cfg(not(target_os = "emscripten"))]
22mod cmd_share;
23#[cfg(not(target_os = "emscripten"))]
24mod cmd_show;
25mod cmd_track;
26mod cmd_validate;
27mod config;
28#[cfg(not(target_os = "emscripten"))]
29mod fuzzy;
30mod io;
31mod kinds;
32mod query;
33mod schema;
34#[cfg(all(not(target_os = "emscripten"), feature = "embedded-picker"))]
35mod skim_picker;
36mod term;
37
38use anyhow::Result;
39use clap::{Parser, Subcommand};
40
41#[derive(Parser, Debug)]
42#[command(name = "path", version)]
43#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
44struct Cli {
45 #[command(subcommand)]
46 command: Commands,
47
48 #[arg(long, global = true)]
50 pretty: bool,
51
52 #[cfg(not(target_os = "emscripten"))]
59 #[arg(long, global = true, value_enum, default_value_t = fuzzy::Picker::Auto)]
60 picker: fuzzy::Picker,
61}
62
63#[derive(Subcommand, Debug)]
64enum Commands {
65 #[cfg(not(target_os = "emscripten"))]
67 Show {
68 #[command(subcommand)]
69 source: cmd_show::ShowSource,
70 #[arg(long)]
74 ansi: bool,
75 },
76 #[cfg(not(target_os = "emscripten"))]
78 Share {
79 #[command(flatten)]
80 args: cmd_share::ShareArgs,
81 },
82 #[cfg(not(target_os = "emscripten"))]
85 Resume {
86 #[command(flatten)]
87 args: cmd_resume::ResumeArgs,
88 },
89 Query {
92 #[command(flatten)]
93 args: cmd_query::QueryArgs,
94 },
95 Kind {
98 #[command(flatten)]
99 args: cmd_kind::KindArgs,
100 },
101 #[cfg(not(target_os = "emscripten"))]
103 Auth {
104 #[command(subcommand)]
105 op: cmd_auth::AuthOp,
106 },
107 P {
111 #[command(subcommand)]
112 command: cmd_p::PCommand,
113 },
114 Haiku,
116}
117
118pub fn run() -> Result<()> {
119 let cli = Cli::parse();
120
121 #[cfg(not(target_os = "emscripten"))]
122 fuzzy::set_picker_override(cli.picker);
123
124 match cli.command {
125 Commands::Haiku => {
126 cmd_haiku::run();
127 Ok(())
128 }
129 #[cfg(not(target_os = "emscripten"))]
130 Commands::Show { source, ansi } => cmd_show::run(source, ansi),
131 #[cfg(not(target_os = "emscripten"))]
132 Commands::Share { args } => cmd_share::run(args),
133 #[cfg(not(target_os = "emscripten"))]
134 Commands::Resume { args } => cmd_resume::run(args),
135 Commands::Query { args } => cmd_query::run(args, cli.pretty),
136 Commands::Kind { args } => cmd_kind::run(args),
137 #[cfg(not(target_os = "emscripten"))]
138 Commands::Auth { op } => cmd_auth::run(op),
139 Commands::P { command } => cmd_p::run(command, cli.pretty),
140 }
141}