mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-09-01 00:59:33 +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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user