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"))]
55 #[arg(long, global = true, value_enum, default_value_t = fuzzy::Picker::Auto)]
56 picker: fuzzy::Picker,
57}
58
59#[derive(Subcommand, Debug)]
60enum Commands {
61 #[cfg(not(target_os = "emscripten"))]
63 Show {
64 #[command(subcommand)]
65 source: cmd_show::ShowSource,
66 #[arg(long)]
70 ansi: bool,
71 },
72 #[cfg(not(target_os = "emscripten"))]
74 Share {
75 #[command(flatten)]
76 args: cmd_share::ShareArgs,
77 },
78 #[cfg(not(target_os = "emscripten"))]
81 Resume {
82 #[command(flatten)]
83 args: cmd_resume::ResumeArgs,
84 },
85 Query {
87 #[command(subcommand)]
88 op: cmd_query::QueryOp,
89 },
90 #[cfg(not(target_os = "emscripten"))]
92 Auth {
93 #[command(subcommand)]
94 op: cmd_auth::AuthOp,
95 },
96 P {
100 #[command(subcommand)]
101 command: cmd_p::PCommand,
102 },
103 Haiku,
105}
106
107pub fn run() -> Result<()> {
108 let cli = Cli::parse();
109
110 #[cfg(not(target_os = "emscripten"))]
111 fuzzy::set_picker_override(cli.picker);
112
113 match cli.command {
114 Commands::Haiku => {
115 cmd_haiku::run();
116 Ok(())
117 }
118 #[cfg(not(target_os = "emscripten"))]
119 Commands::Show { source, ansi } => cmd_show::run(source, ansi),
120 #[cfg(not(target_os = "emscripten"))]
121 Commands::Share { args } => cmd_share::run(args),
122 #[cfg(not(target_os = "emscripten"))]
123 Commands::Resume { args } => cmd_resume::run(args),
124 Commands::Query { op } => cmd_query::run(op, cli.pretty),
125 #[cfg(not(target_os = "emscripten"))]
126 Commands::Auth { op } => cmd_auth::run(op),
127 Commands::P { command } => cmd_p::run(command, cli.pretty),
128 }
129}