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;
11mod cmd_p;
12#[cfg(not(target_os = "emscripten"))]
13mod cmd_pathbase;
14mod cmd_project;
15mod cmd_query;
16mod cmd_render;
17#[cfg(not(target_os = "emscripten"))]
18pub mod cmd_resume;
19#[cfg(not(target_os = "emscripten"))]
20mod cmd_share;
21#[cfg(not(target_os = "emscripten"))]
22mod cmd_show;
23mod cmd_track;
24mod cmd_validate;
25mod config;
26#[cfg(not(target_os = "emscripten"))]
27mod fuzzy;
28mod io;
29mod schema;
30#[cfg(all(not(target_os = "emscripten"), feature = "embedded-picker"))]
31mod skim_picker;
32mod term;
33
34use anyhow::Result;
35use clap::{Parser, Subcommand};
36
37#[derive(Parser, Debug)]
38#[command(name = "path", version)]
39#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
40struct Cli {
41 #[command(subcommand)]
42 command: Commands,
43
44 #[arg(long, global = true)]
46 pretty: bool,
47
48 #[cfg(not(target_os = "emscripten"))]
54 #[arg(long, global = true, value_enum, default_value_t = fuzzy::Picker::Auto)]
55 picker: fuzzy::Picker,
56}
57
58#[derive(Subcommand, Debug)]
59enum Commands {
60 #[cfg(not(target_os = "emscripten"))]
62 Show {
63 #[command(subcommand)]
64 source: cmd_show::ShowSource,
65 #[arg(long)]
69 ansi: bool,
70 },
71 #[cfg(not(target_os = "emscripten"))]
73 Share {
74 #[command(flatten)]
75 args: cmd_share::ShareArgs,
76 },
77 #[cfg(not(target_os = "emscripten"))]
80 Resume {
81 #[command(flatten)]
82 args: cmd_resume::ResumeArgs,
83 },
84 Query {
86 #[command(subcommand)]
87 op: cmd_query::QueryOp,
88 },
89 #[cfg(not(target_os = "emscripten"))]
91 Auth {
92 #[command(subcommand)]
93 op: cmd_auth::AuthOp,
94 },
95 P {
99 #[command(subcommand)]
100 command: cmd_p::PCommand,
101 },
102 Haiku,
104}
105
106pub fn run() -> Result<()> {
107 let cli = Cli::parse();
108
109 #[cfg(not(target_os = "emscripten"))]
110 fuzzy::set_picker_override(cli.picker);
111
112 match cli.command {
113 Commands::Haiku => {
114 cmd_haiku::run();
115 Ok(())
116 }
117 #[cfg(not(target_os = "emscripten"))]
118 Commands::Show { source, ansi } => cmd_show::run(source, ansi),
119 #[cfg(not(target_os = "emscripten"))]
120 Commands::Share { args } => cmd_share::run(args),
121 #[cfg(not(target_os = "emscripten"))]
122 Commands::Resume { args } => cmd_resume::run(args),
123 Commands::Query { op } => cmd_query::run(op, cli.pretty),
124 #[cfg(not(target_os = "emscripten"))]
125 Commands::Auth { op } => cmd_auth::run(op),
126 Commands::P { command } => cmd_p::run(command, cli.pretty),
127 }
128}