Skip to main content

path_cli/
lib.rs

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;
24mod schema;
25
26use anyhow::Result;
27use clap::{Parser, Subcommand};
28use std::path::PathBuf;
29
30#[derive(Parser, Debug)]
31#[command(name = "path", version)]
32#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
33struct Cli {
34    #[command(subcommand)]
35    command: Commands,
36
37    /// Pretty-print JSON output
38    #[arg(long, global = true)]
39    pretty: bool,
40}
41
42#[derive(Subcommand, Debug)]
43enum Commands {
44    /// List available sources (branches, projects, sessions)
45    List {
46        #[command(subcommand)]
47        source: cmd_list::ListSource,
48
49        /// Output format (default: pretty when stdout is a TTY, tsv when piped)
50        #[arg(long, global = true, value_enum)]
51        format: Option<cmd_list::ListFormat>,
52
53        /// Output as JSON (deprecated alias for --format json)
54        #[arg(long, global = true)]
55        json: bool,
56    },
57    /// Import from external formats into the toolpath cache
58    Import {
59        #[command(flatten)]
60        args: cmd_import::ImportArgs,
61    },
62    /// Export toolpath documents into external formats
63    Export {
64        #[command(subcommand)]
65        target: cmd_export::ExportTarget,
66    },
67    /// Manage the on-disk document cache (~/.toolpath/documents/)
68    Cache {
69        #[command(subcommand)]
70        op: cmd_cache::CacheOp,
71    },
72    /// Query Toolpath documents
73    Query {
74        #[command(subcommand)]
75        op: cmd_query::QueryOp,
76    },
77    /// Render Toolpath documents to other formats
78    Render {
79        #[command(subcommand)]
80        format: cmd_render::RenderFormat,
81    },
82    /// Show a single session as a markdown summary (used by fzf preview)
83    #[cfg(not(target_os = "emscripten"))]
84    Show {
85        #[command(subcommand)]
86        source: cmd_show::ShowSource,
87    },
88    /// Merge multiple Toolpath documents into a single Graph
89    Merge {
90        /// Input files (use - for stdin)
91        #[arg(required = true)]
92        inputs: Vec<String>,
93
94        /// Title for the merged graph
95        #[arg(long)]
96        title: Option<String>,
97    },
98    /// Incrementally build a Toolpath Path document
99    Track {
100        #[command(subcommand)]
101        op: cmd_track::TrackOp,
102    },
103    /// Validate a Toolpath document
104    Validate {
105        /// Input file
106        #[arg(short, long)]
107        input: PathBuf,
108    },
109    /// Print a random Toolpath haiku
110    Haiku,
111    /// Manage Pathbase credentials for trace uploads
112    #[cfg(not(target_os = "emscripten"))]
113    Auth {
114        #[command(subcommand)]
115        op: cmd_auth::AuthOp,
116    },
117
118    // ── Deprecated aliases ────────────────────────────────────────────
119    #[command(hide = true, about = "[deprecated] Use `path import`")]
120    Derive {
121        #[command(subcommand)]
122        source: cmd_derive::DeriveSource,
123    },
124    #[command(hide = true, about = "[deprecated] Use `path export claude`")]
125    Incept {
126        #[command(flatten)]
127        args: cmd_incept::InceptArgs,
128    },
129    #[command(hide = true, about = "[deprecated] Use `path export`")]
130    Project {
131        #[command(subcommand)]
132        target: cmd_project::ProjectTarget,
133    },
134}
135
136pub fn run() -> Result<()> {
137    let cli = Cli::parse();
138
139    match cli.command {
140        Commands::List {
141            source,
142            format,
143            json,
144        } => cmd_list::run(source, format, json),
145        Commands::Import { args } => cmd_import::run(args, cli.pretty),
146        Commands::Export { target } => cmd_export::run(target),
147        Commands::Cache { op } => cmd_cache::run(op),
148        Commands::Query { op } => cmd_query::run(op, cli.pretty),
149        Commands::Render { format } => cmd_render::run(format),
150        #[cfg(not(target_os = "emscripten"))]
151        Commands::Show { source } => cmd_show::run(source),
152        Commands::Merge { inputs, title } => cmd_merge::run(inputs, title, cli.pretty),
153        Commands::Track { op } => cmd_track::run(op, cli.pretty),
154        Commands::Validate { input } => cmd_validate::run(input),
155        Commands::Haiku => {
156            cmd_haiku::run();
157            Ok(())
158        }
159        #[cfg(not(target_os = "emscripten"))]
160        Commands::Auth { op } => cmd_auth::run(op),
161
162        Commands::Derive { source } => cmd_derive::run(source, cli.pretty),
163        Commands::Incept { args } => cmd_incept::run(args),
164        Commands::Project { target } => cmd_project::run(target),
165    }
166}