Skip to content

Commit 3f16e18

Browse files
committed
fix: chat --help
1 parent 200f16c commit 3f16e18

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,18 @@ impl Cli {
344344
CliRootCommands::Telemetry(subcommand) => subcommand.execute().await,
345345
CliRootCommands::Version { changelog } => Self::print_version(changelog),
346346
CliRootCommands::Dashboard => launch_dashboard(false).await,
347-
CliRootCommands::Chat { args } => Self::execute_chat(Some(args)).await,
347+
CliRootCommands::Chat { args } => Self::execute_chat(Some(args), true).await,
348348
CliRootCommands::Inline(subcommand) => subcommand.execute(&cli_context).await,
349349
},
350350
// Root command
351-
None => Self::execute_chat(None).await,
351+
None => Self::execute_chat(None, true).await,
352352
}
353353
}
354354

355-
async fn execute_chat(args: Option<Vec<String>>) -> Result<ExitCode> {
356-
assert_logged_in().await?;
355+
pub async fn execute_chat(args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
356+
if enforce_login {
357+
assert_logged_in().await?;
358+
}
357359

358360
let secret_store = SecretStore::new().await.ok();
359361
if let Some(secret_store) = secret_store {

crates/q_cli/src/main.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,26 @@ fn main() -> Result<ExitCode> {
2626
fig_telemetry::set_dispatch_mode(fig_telemetry::DispatchMode::On);
2727
fig_telemetry::init_global_telemetry_emitter();
2828

29+
let mut args = std::env::args();
30+
let subcommand = args.nth(1);
2931
let multithread = matches!(
30-
std::env::args().nth(1).as_deref(),
32+
subcommand.as_deref(),
3133
Some("init" | "_" | "internal" | "completion" | "hook" | "chat")
3234
);
3335

36+
let runtime = if multithread {
37+
tokio::runtime::Builder::new_multi_thread()
38+
} else {
39+
tokio::runtime::Builder::new_current_thread()
40+
}
41+
.enable_all()
42+
.build()?;
43+
44+
// Hack as clap doesn't expose a custom command help.
45+
if subcommand.as_deref() == Some("chat") && args.next().as_deref() == Some("--help") {
46+
runtime.block_on(cli::Cli::execute_chat(Some(vec!["--help".to_owned()]), true))?;
47+
}
48+
3449
let parsed = match cli::Cli::try_parse() {
3550
Ok(cli) => cli,
3651
Err(err) => {
@@ -58,14 +73,6 @@ fn main() -> Result<ExitCode> {
5873

5974
let verbose = parsed.verbose > 0;
6075

61-
let runtime = if multithread {
62-
tokio::runtime::Builder::new_multi_thread()
63-
} else {
64-
tokio::runtime::Builder::new_current_thread()
65-
}
66-
.enable_all()
67-
.build()?;
68-
6976
let result = runtime.block_on(async {
7077
let result = parsed.execute().await;
7178
fig_telemetry::finish_telemetry().await;

0 commit comments

Comments
 (0)