Skip to content

Commit 0a8eb2d

Browse files
authored
Redirect q settings list cmd to qchat (#832)
1 parent 84bfe74 commit 0a8eb2d

File tree

5 files changed

+89
-54
lines changed

5 files changed

+89
-54
lines changed

crates/chat-cli/src/cli/chat/tool_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl ToolManager {
10001000
Ok(candidates.first().map(|s| s.as_str()).unwrap())
10011001
} else if candidates.len() > 1 {
10021002
let mut content = candidates.iter().fold(
1003-
"There are multilple tools with given tool name: ".to_string(),
1003+
"There are multiple tools with given tool name: ".to_string(),
10041004
|mut acc, name| {
10051005
acc.push_str(name);
10061006
acc.push_str(", ");

crates/fig_integrations/src/file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ mod tests {
134134
integration.describe()
135135
);
136136

137-
// ensure no intgration is marked as not installed
137+
// ensure no integration is marked as not installed
138138
assert!(matches!(
139139
integration.is_installed().await,
140140
Err(Error::FileDoesNotExist(_))
141141
));
142142

143-
// ensure the intgration can be installed
143+
// ensure the integration can be installed
144144
integration.install().await.unwrap();
145145
assert!(integration.is_installed().await.is_ok());
146146

147-
// ensure the intgration can be installed while already installed
147+
// ensure the integration can be installed while already installed
148148
integration.install().await.unwrap();
149149
assert!(integration.is_installed().await.is_ok());
150150

151-
// ensure the intgration can be uninstalled
151+
// ensure the integration can be uninstalled
152152
integration.uninstall().await.unwrap();
153153
assert!(matches!(
154154
integration.is_installed().await,

crates/q_cli/src/cli/mod.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::io::{
2525
Write as _,
2626
stdout,
2727
};
28-
use std::path::PathBuf;
2928
use std::process::ExitCode;
3029

3130
use anstream::{
@@ -61,7 +60,6 @@ use fig_log::{
6160
};
6261
use fig_proto::local::UiElement;
6362
use fig_settings::sqlite::database;
64-
use fig_util::directories::home_local_bin;
6563
use fig_util::{
6664
CLI_BINARY_NAME,
6765
PRODUCT_NAME,
@@ -88,6 +86,7 @@ use crate::util::desktop::{
8886
use crate::util::{
8987
CliContext,
9088
assert_logged_in,
89+
qchat_path,
9190
};
9291

9392
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
@@ -599,37 +598,6 @@ async fn launch_dashboard(help_fallback: bool) -> Result<ExitCode> {
599598
Ok(ExitCode::SUCCESS)
600599
}
601600

602-
#[cfg(target_os = "linux")]
603-
fn qchat_path() -> Result<PathBuf> {
604-
use fig_os_shim::Context;
605-
use fig_util::consts::CHAT_BINARY_NAME;
606-
607-
let ctx = Context::new();
608-
if let Some(path) = ctx.process_info().current_pid().exe() {
609-
// This is required for deb installations.
610-
if path.starts_with("/usr/bin") {
611-
return Ok(PathBuf::from("/usr/bin").join(CHAT_BINARY_NAME));
612-
}
613-
}
614-
615-
if let Ok(local_bin_path) = home_local_bin() {
616-
let local_bin_path = local_bin_path.join(CHAT_BINARY_NAME);
617-
if local_bin_path.exists() {
618-
return Ok(local_bin_path);
619-
}
620-
}
621-
622-
Ok(PathBuf::from(CHAT_BINARY_NAME))
623-
}
624-
625-
#[cfg(target_os = "macos")]
626-
fn qchat_path() -> Result<PathBuf> {
627-
use fig_util::consts::CHAT_BINARY_NAME;
628-
use macos_utils::bundle::get_bundle_path_for_executable;
629-
630-
Ok(get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME)))
631-
}
632-
633601
#[cfg(test)]
634602
mod test {
635603
use super::*;

crates/q_cli/src/cli/settings.rs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use clap::{
66
Args,
77
Parser,
88
Subcommand,
9+
ValueEnum,
910
};
1011
use eyre::{
1112
Result,
@@ -35,13 +36,24 @@ use crate::util::desktop::{
3536
use crate::util::{
3637
CliContext,
3738
app_not_running_message,
39+
qchat_path,
3840
};
3941

4042
#[derive(Debug, Subcommand, PartialEq, Eq)]
4143
pub enum SettingsSubcommands {
4244
/// Open the settings file
4345
Open,
44-
/// List all the settings
46+
/// List settings
47+
List {
48+
/// Show all available settings
49+
#[arg(long)]
50+
all: bool,
51+
/// Format of the output
52+
#[arg(long, short, value_enum, default_value_t)]
53+
format: OutputFormat,
54+
},
55+
/// List configured settings
56+
#[command(hide = true)]
4557
All {
4658
/// Format of the output
4759
#[arg(long, short, value_enum, default_value_t)]
@@ -52,15 +64,15 @@ pub enum SettingsSubcommands {
5264
#[derive(Debug, Args, PartialEq, Eq)]
5365
#[command(subcommand_negates_reqs = true)]
5466
#[command(args_conflicts_with_subcommands = true)]
55-
#[command(group(ArgGroup::new("vals").requires("key").args(&["value", "delete", "format"])))]
67+
#[command(group(ArgGroup::new("vals").requires("key").args(&["value", "format"])))]
5668
pub struct SettingsArgs {
5769
#[command(subcommand)]
5870
cmd: Option<SettingsSubcommands>,
5971
/// key
6072
key: Option<String>,
6173
/// value
6274
value: Option<String>,
63-
/// Delete a value
75+
/// Delete a key (No value needed)
6476
#[arg(long, short)]
6577
delete: bool,
6678
/// Format of the output
@@ -89,25 +101,45 @@ impl SettingsArgs {
89101
bail!("The EDITOR environment variable is not set")
90102
}
91103
},
104+
Some(SettingsSubcommands::List { all, format }) => {
105+
let mut args = vec!["settings".to_string(), "list".to_string()];
106+
if all {
107+
args.push("--all".to_string());
108+
}
109+
if format != OutputFormat::default() {
110+
args.push("--format".to_string());
111+
args.push(format.to_possible_value().unwrap().get_name().to_string());
112+
}
113+
114+
let status = tokio::process::Command::new(qchat_path()?).args(&args).status().await?;
115+
116+
Ok(if status.success() {
117+
ExitCode::SUCCESS
118+
} else {
119+
ExitCode::FAILURE
120+
})
121+
},
92122
Some(SettingsSubcommands::All { format }) => {
93-
let settings = fig_settings::OldSettings::load()?.map().clone();
123+
let mut args = vec!["settings".to_string(), "list".to_string()];
94124

95-
match format {
96-
OutputFormat::Plain => {
97-
for (key, value) in settings {
98-
println!("{key} = {value}");
99-
}
100-
},
101-
OutputFormat::Json => println!("{}", serde_json::to_string(&settings)?),
102-
OutputFormat::JsonPretty => {
103-
println!("{}", serde_json::to_string_pretty(&settings)?);
104-
},
125+
if format != OutputFormat::default() {
126+
args.push("--format".to_string());
127+
args.push(format.to_possible_value().unwrap().get_name().to_string());
105128
}
106129

107-
Ok(ExitCode::SUCCESS)
130+
let status = tokio::process::Command::new(qchat_path()?).args(&args).status().await?;
131+
132+
Ok(if status.success() {
133+
ExitCode::SUCCESS
134+
} else {
135+
ExitCode::FAILURE
136+
})
108137
},
109138
None => match &self.key {
110139
Some(key) => match (&self.value, self.delete) {
140+
(Some(_), true) => Err(eyre::eyre!(
141+
"the argument '--delete' cannot be used with '[VALUE]'\n Usage: q settings --delete {key}"
142+
)),
111143
(None, false) => match fig_settings::settings::get_value(key)? {
112144
Some(value) => {
113145
match self.format {
@@ -161,9 +193,14 @@ impl SettingsArgs {
161193

162194
Ok(ExitCode::SUCCESS)
163195
},
164-
_ => Ok(ExitCode::SUCCESS),
165196
},
166197
None => {
198+
if self.delete {
199+
return Err(eyre::eyre!(
200+
"the argument '--delete' requires a <KEY>\n Usage: q settings --delete <KEY>"
201+
));
202+
}
203+
167204
if manifest::is_minimal() || system_info::is_remote() {
168205
Cli::parse_from([CLI_BINARY_NAME, "settings", "--help"]);
169206
return Ok(ExitCode::SUCCESS);

crates/q_cli/src/util/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ use eyre::{
3838
};
3939
use fig_ipc::local::quit_command;
4040
use fig_util::consts::APP_BUNDLE_ID;
41+
use fig_util::directories::home_local_bin;
4142
use fig_util::{
43+
CHAT_BINARY_NAME,
4244
CLI_BINARY_NAME,
4345
PRODUCT_NAME,
4446
};
@@ -124,6 +126,34 @@ pub fn app_path_from_bundle_id(bundle_id: impl AsRef<OsStr>) -> Option<String> {
124126
}
125127
}
126128

129+
#[cfg(target_os = "linux")]
130+
pub fn qchat_path() -> Result<PathBuf> {
131+
use fig_os_shim::Context;
132+
133+
let ctx = Context::new();
134+
if let Some(path) = ctx.process_info().current_pid().exe() {
135+
// This is required for deb installations.
136+
if path.starts_with("/usr/bin") {
137+
return Ok(PathBuf::from("/usr/bin").join(CHAT_BINARY_NAME));
138+
}
139+
}
140+
141+
if let Ok(local_bin_path) = home_local_bin() {
142+
let local_bin_path = local_bin_path.join(CHAT_BINARY_NAME);
143+
if local_bin_path.exists() {
144+
return Ok(local_bin_path);
145+
}
146+
}
147+
148+
Ok(PathBuf::from(CHAT_BINARY_NAME))
149+
}
150+
151+
#[cfg(target_os = "macos")]
152+
pub fn qchat_path() -> Result<PathBuf> {
153+
use macos_utils::bundle::get_bundle_path_for_executable;
154+
155+
Ok(get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME)))
156+
}
127157
pub async fn quit_fig(verbose: bool) -> Result<ExitCode> {
128158
if fig_util::system_info::in_cloudshell() {
129159
bail!("Restarting {PRODUCT_NAME} is not supported in CloudShell");

0 commit comments

Comments
 (0)