Skip to content

Commit 287c11c

Browse files
committed
Add a flag and write a wrapper script to redirect all old q calls to kirocli with a warning both install and update
1 parent 07dff2d commit 287c11c

File tree

7 files changed

+105
-7
lines changed

7 files changed

+105
-7
lines changed

crates/fig_install/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub async fn uninstall(components: InstallComponents, ctx: Arc<Context>) -> Resu
7272
// let folders = [directories::home_local_bin()?, Path::new("/usr/local/bin").into()];
7373
let folders = [directories::home_local_bin()?];
7474

75-
let mut all_binary_names = vec![CLI_BINARY_NAME, CHAT_BINARY_NAME, PTY_BINARY_NAME];
75+
let mut all_binary_names = vec![CLI_BINARY_NAME, CHAT_BINARY_NAME, PTY_BINARY_NAME, "q"];
7676
all_binary_names.extend(OLD_CLI_BINARY_NAMES);
7777
all_binary_names.extend(OLD_PTY_BINARY_NAMES);
7878

crates/fig_install/src/linux.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ async fn replace_bins(bin_dir: &Path) -> Result<(), Error> {
110110
}
111111
}
112112
}
113+
114+
// Create legacy q wrapper script after updating binaries
115+
if let Err(err) = fig_util::wrapper::create_q_wrapper(&local_bin).await {
116+
tracing::warn!("Failed to create q wrapper: {}", err);
117+
}
118+
113119
res
114120
}
115121

crates/fig_util/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod process_info;
55
mod shell;
66
pub mod system_info;
77
pub mod terminal;
8+
pub mod wrapper;
89

910
pub mod consts;
1011
#[cfg(target_os = "macos")]

crates/fig_util/src/wrapper.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::path::Path;
2+
3+
use crate::Error;
4+
5+
/// Create legacy q wrapper script for backward compatibility
6+
pub async fn create_q_wrapper(install_dir: &Path) -> Result<(), Error> {
7+
let wrapper_path = install_dir.join("q");
8+
9+
// Check what exists and handle appropriately
10+
if wrapper_path.exists() {
11+
let metadata = tokio::fs::symlink_metadata(&wrapper_path).await?;
12+
13+
if metadata.is_symlink() {
14+
// It's a symlink (likely from old installation) - safe to replace
15+
tokio::fs::remove_file(&wrapper_path).await?;
16+
} else if is_our_wrapper(&wrapper_path).await? {
17+
// It's our wrapper from previous install - safe to replace
18+
tokio::fs::remove_file(&wrapper_path).await?;
19+
} else {
20+
// It's something else (assume old Q CLI) - safe to replace per our assumption
21+
tokio::fs::remove_file(&wrapper_path).await?;
22+
}
23+
}
24+
25+
// Create wrapper script content
26+
let wrapper_content = format!(
27+
"#!/bin/sh\n\"{}/kiro-cli\" --show-legacy-warning \"$@\"\n",
28+
install_dir.display()
29+
);
30+
31+
// Write wrapper script
32+
tokio::fs::write(&wrapper_path, wrapper_content).await?;
33+
34+
// Make executable
35+
#[cfg(unix)]
36+
{
37+
use std::os::unix::fs::PermissionsExt;
38+
let mut perms = tokio::fs::metadata(&wrapper_path).await?.permissions();
39+
perms.set_mode(0o755);
40+
tokio::fs::set_permissions(&wrapper_path, perms).await?;
41+
}
42+
43+
Ok(())
44+
}
45+
46+
/// Check if the existing q command is our wrapper script
47+
async fn is_our_wrapper(path: &Path) -> Result<bool, Error> {
48+
if let Ok(content) = tokio::fs::read_to_string(path).await {
49+
// Check if it contains our signature
50+
Ok(content.contains("--show-legacy-warning") && content.contains("kiro-cli"))
51+
} else {
52+
Ok(false)
53+
}
54+
}

crates/q_cli/src/cli/internal/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,11 @@ impl InternalSubcommand {
777777
tokio::time::sleep(Duration::from_millis(200)).await;
778778
}
779779

780+
// Create legacy q wrapper script for backward compatibility
781+
if let Err(err) = fig_util::wrapper::create_q_wrapper(&fig_util::directories::home_local_bin()?).await {
782+
tracing::warn!("Failed to create q wrapper: {}", err);
783+
}
784+
780785
launch_fig_desktop(LaunchArgs {
781786
wait_for_socket: false,
782787
open_dashboard: relaunch_dashboard,

crates/q_cli/src/cli/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ use crate::util::{
8989
is_logged_in_check,
9090
};
9191

92+
const LEGACY_WARNING: &str = "Warn: Q CLI is now Kiro CLI and should be invoked as kiro-cli rather than q";
93+
9294
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
9395
pub enum OutputFormat {
9496
/// Outputs the results as markdown
@@ -292,10 +294,18 @@ pub struct Cli {
292294
/// Print help for all subcommands
293295
#[arg(long)]
294296
help_all: bool,
297+
/// Show legacy warning for q command
298+
#[arg(long, hide = true, default_value = "false")]
299+
show_legacy_warning: bool,
295300
}
296301

297302
impl Cli {
298303
pub async fn execute(self) -> Result<ExitCode> {
304+
// Show legacy warning if flag is set
305+
if self.show_legacy_warning {
306+
eprintln!("{}", LEGACY_WARNING);
307+
}
308+
299309
// Initialize our logger and keep around the guard so logging can perform as expected.
300310
let _log_guard = initialize_logging(LogArgs {
301311
log_level: match self.verbose > 0 {
@@ -698,21 +708,18 @@ mod test {
698708
#[test]
699709
fn test_flags() {
700710
assert_eq!(Cli::parse_from([CLI_BINARY_NAME, "-v"]), Cli {
701-
subcommand: None,
702711
verbose: 1,
703-
help_all: false,
712+
..Default::default()
704713
});
705714

706715
assert_eq!(Cli::parse_from([CLI_BINARY_NAME, "-vvv"]), Cli {
707-
subcommand: None,
708716
verbose: 3,
709-
help_all: false,
717+
..Default::default()
710718
});
711719

712720
assert_eq!(Cli::parse_from([CLI_BINARY_NAME, "--help-all"]), Cli {
713-
subcommand: None,
714-
verbose: 0,
715721
help_all: true,
722+
..Default::default()
716723
});
717724
}
718725

scripts/install.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,23 @@ create_symlink() {
318318
ln -s "$src" "$dst"
319319
}
320320

321+
# Create legacy q wrapper script
322+
create_q_wrapper() {
323+
local install_dir="$1"
324+
local wrapper_path="$install_dir/q"
325+
326+
# Remove existing q command if it exists
327+
rm -f "$wrapper_path"
328+
329+
# Create wrapper script
330+
cat > "$wrapper_path" << EOF
331+
#!/bin/sh
332+
"$install_dir/kiro-cli" --show-legacy-warning "\$@"
333+
EOF
334+
335+
chmod +x "$wrapper_path"
336+
}
337+
321338
# Install on macOS
322339
install_macos() {
323340
local dmg_path="$1"
@@ -461,6 +478,14 @@ main() {
461478
install_linux "$downloaded_file"
462479
fi
463480

481+
# Create legacy q wrapper script
482+
log "Creating legacy q wrapper..."
483+
if [[ "$os" == "macos" ]]; then
484+
create_q_wrapper "$HOME/.local/bin"
485+
else
486+
create_q_wrapper "$LINUX_INSTALL_DIR"
487+
fi
488+
464489
SUCCESS=true
465490

466491
echo

0 commit comments

Comments
 (0)