posthog_cli/commands/
mod.rs1pub mod login;
2pub mod query;
3pub mod sourcemap;
4
5use clap::{Parser, Subcommand};
6use query::OutputMode;
7use std::path::PathBuf;
8
9use crate::error::CapturedError;
10
11#[derive(Parser)]
12#[command(version, about, long_about = None)]
13pub struct Cli {
14 #[arg(long, default_value = "https://us.posthog.com")]
16 host: String,
17
18 #[command(subcommand)]
19 command: Commands,
20}
21
22#[derive(Subcommand)]
23pub enum Commands {
24 Login,
26
27 Query {
29 query: String,
31 #[arg(short, long, default_value = "print", value_enum)]
32 output: OutputMode,
33 },
34
35 #[command(about = "Upload a directory of bundled chunks to PostHog")]
36 Sourcemap {
37 #[command(subcommand)]
38 cmd: SourcemapCommand,
39 },
40}
41
42#[derive(Subcommand)]
43pub enum SourcemapCommand {
44 Inject {
46 #[arg(short, long)]
48 directory: PathBuf,
49
50 #[arg(short, long)]
52 output: Option<PathBuf>,
53 },
54 Upload {
56 #[arg(short, long)]
58 directory: PathBuf,
59
60 #[arg(short, long)]
62 build: Option<String>,
63 },
64}
65
66impl Cli {
67 pub fn run() -> Result<(), CapturedError> {
68 let command = Cli::parse();
69
70 match &command.command {
71 Commands::Login => {
72 login::login()?;
73 }
74 Commands::Sourcemap { cmd } => match cmd {
75 SourcemapCommand::Inject { directory, output } => {
76 sourcemap::inject::inject(directory, output)?;
77 }
78 SourcemapCommand::Upload { directory, build } => {
79 sourcemap::upload::upload(&command.host, directory, build)?;
80 }
81 },
82 Commands::Query { query, output } => query::run_query(&command.host, query, *output)?,
83 }
84
85 Ok(())
86 }
87}