mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-27 08:00:17 +00:00
Feat/completion (#240)
* feat: add OpenRouter usage examples * feat: add HTPS headers * feat: add shell completion generation via clap_complete * feat: add shell completion generation via clap_complete * feat: add shell completion generation via clap_complete * Refactor completion: use clap_complete::Shell directly, improve tests, remove tracing duplication, fix .env.example and Cargo.toml * fix: rename init_cli_logging to init_cli_tracing (sync with main) --------- Co-authored-by: BroccoliFin <[email protected]> Co-authored-by: firat.sertgoz <[email protected]>
This commit is contained in:
co-authored by
BroccoliFin
firat.sertgoz
parent
b8901baafd
commit
7f68207f1e
@@ -0,0 +1,39 @@
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap_complete::{Shell, generate};
|
||||
use std::io;
|
||||
|
||||
/// Generate shell completion scripts for ironclaw
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Completion {
|
||||
/// The shell to generate completions for
|
||||
#[arg(value_enum, long)]
|
||||
pub shell: Shell,
|
||||
}
|
||||
|
||||
impl Completion {
|
||||
pub fn run(&self) -> anyhow::Result<()> {
|
||||
let mut cmd = crate::cli::Cli::command();
|
||||
let bin_name = cmd.get_name().to_string();
|
||||
|
||||
// Generated and output script to stdout
|
||||
generate(self.shell, &mut cmd, bin_name, &mut io::stdout());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use clap::CommandFactory;
|
||||
|
||||
#[test]
|
||||
fn test_run_generates_output() {
|
||||
let completion = Completion { shell: Shell::Zsh };
|
||||
let mut cmd = crate::cli::Cli::command();
|
||||
let bin_name = cmd.get_name().to_string();
|
||||
let mut buf = Vec::new();
|
||||
generate(completion.shell, &mut cmd, bin_name, &mut buf);
|
||||
assert!(!buf.is_empty(), "generate() should produce output");
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
//! - Active health diagnostics (`doctor`)
|
||||
//! - Checking system health (`status`)
|
||||
|
||||
mod completion;
|
||||
mod config;
|
||||
mod doctor;
|
||||
mod mcp;
|
||||
@@ -22,6 +23,7 @@ mod service;
|
||||
pub mod status;
|
||||
mod tool;
|
||||
|
||||
pub use completion::Completion;
|
||||
pub use config::{ConfigCommand, run_config_command};
|
||||
pub use doctor::run_doctor_command;
|
||||
pub use mcp::{McpCommand, run_mcp_command};
|
||||
@@ -118,6 +120,9 @@ pub enum Command {
|
||||
/// Show system health and diagnostics
|
||||
Status,
|
||||
|
||||
/// Generate shell completion scripts
|
||||
Completion(Completion),
|
||||
|
||||
/// Run as a sandboxed worker inside a Docker container (internal use).
|
||||
/// This is invoked automatically by the orchestrator, not by users directly.
|
||||
Worker {
|
||||
|
||||
Reference in New Issue
Block a user