aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-ai/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/atuin-ai/src/commands.rs')
-rw-r--r--crates/atuin-ai/src/commands.rs71
1 files changed, 58 insertions, 13 deletions
diff --git a/crates/atuin-ai/src/commands.rs b/crates/atuin-ai/src/commands.rs
index 56741544..7d5ca16b 100644
--- a/crates/atuin-ai/src/commands.rs
+++ b/crates/atuin-ai/src/commands.rs
@@ -1,7 +1,11 @@
+use atuin_common::shell::Shell;
use clap::{Parser, Subcommand};
use tracing::Level;
use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt};
+#[cfg(debug_assertions)]
+pub mod debug_render;
+
pub mod init;
pub mod inline;
@@ -16,6 +20,10 @@ struct Cli {
#[arg(long, global = true, env = "ATUIN_AI_API_ENDPOINT")]
api_endpoint: Option<String>,
+ /// Custom API token
+ #[arg(long, global = true, env = "ATUIN_AI_API_TOKEN")]
+ api_token: Option<String>,
+
#[command(subcommand)]
command: Commands,
}
@@ -23,13 +31,10 @@ struct Cli {
#[derive(Subcommand, Debug)]
enum Commands {
/// Initialize shell integration
- Init,
-
- /// Complete current command line
- Complete {
- /// Current command line to complete
- #[arg(value_name = "COMMAND")]
- command: Option<String>,
+ Init {
+ /// Shell to generate integration for; defaults to "auto"
+ #[arg(value_name = "SHELL", default_value = "auto")]
+ shell: String,
},
/// Inline completion mode with small TUI overlay
@@ -41,10 +46,27 @@ enum Commands {
/// Start in natural language mode
#[arg(long)]
natural_language: bool,
+
+ /// Keep TUI output visible after exit (default: erase)
+ #[arg(long)]
+ keep: bool,
+
+ /// Log state changes to file for debugging (dev tool)
+ #[arg(long, value_name = "FILE")]
+ debug_state: Option<String>,
},
- /// Interactive mode with TUI
- Interactive,
+ /// Debug render: output a single frame from JSON state (dev tool)
+ #[cfg(debug_assertions)]
+ DebugRender {
+ /// Input file (reads from stdin if not provided)
+ #[arg(short, long)]
+ input: Option<String>,
+
+ /// Output format: ansi (default), plain, json
+ #[arg(short, long, default_value = "ansi")]
+ format: String,
+ },
}
pub async fn run() -> eyre::Result<()> {
@@ -53,13 +75,32 @@ pub async fn run() -> eyre::Result<()> {
init_tracing(cli.verbose);
match cli.command {
- Commands::Init => init::run().await,
+ Commands::Init { shell } => init::run(shell).await,
Commands::Inline {
command,
natural_language,
- } => inline::run(command, natural_language, cli.api_endpoint).await,
- Commands::Complete { command } => inline::run(command, false, cli.api_endpoint).await,
- Commands::Interactive => Err(eyre::eyre!("interactive mode not implemented yet")),
+ keep,
+ debug_state,
+ } => {
+ inline::run(
+ command,
+ natural_language,
+ cli.api_endpoint,
+ cli.api_token,
+ keep,
+ debug_state,
+ )
+ .await
+ }
+ #[cfg(debug_assertions)]
+ Commands::DebugRender { input, format } => {
+ let output_format = match format.as_str() {
+ "plain" => debug_render::OutputFormat::Plain,
+ "json" => debug_render::OutputFormat::Json,
+ _ => debug_render::OutputFormat::Ansi,
+ };
+ debug_render::run(input, output_format).await
+ }
}
}
@@ -95,3 +136,7 @@ fn init_tracing(verbose: bool) {
subscriber.init();
}
}
+
+pub fn detect_shell() -> Option<String> {
+ Some(Shell::current().to_string())
+}