Skip to content

Commit 6c75d35

Browse files
committed
feat: interactive use command support
1 parent 6ddbc74 commit 6c75d35

File tree

5 files changed

+715
-8
lines changed

5 files changed

+715
-8
lines changed

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,47 @@ Before you can do anything productive with `slic`, you need to tell it which
175175
project you wish to use and then you can initialize the project, run tests, and
176176
execute other commands to your heart's content!
177177

178-
Assuming you have a plugin called `the-events-calendar` in the plugins directory
179-
where you ran `slic here`, you can tell `slic` you want to take actions on that
180-
plugin using the following command:
178+
The `slic use` command offers two ways to select your target:
179+
180+
#### Interactive Mode (No Arguments)
181+
182+
When you run `slic use` without any arguments, it opens an interactive Terminal User Interface (TUI) that lets you browse and select from available targets:
181183

182184
```bash
183-
slic use the-events-calendar
185+
slic use
184186
```
185187

186-
> For more information on this command, run `slic help use`.
188+
This launches an interactive menu with these features:
189+
- **Browse targets**: Navigate through all available plugins/themes with arrow keys (↑↓)
190+
- **Fuzzy search**: Type to filter targets instantly (case-insensitive substring matching)
191+
- **Current target indicator**: See which target is currently active (marked with ✓)
192+
- **Scroll indicators**: Visual cues when there are more items above/below the visible window
193+
- **Keyboard controls**:
194+
- `↑↓` Arrow keys to navigate
195+
- Type to filter/search
196+
- `Enter` to select
197+
- `ESC` or `Ctrl+C` to cancel
198+
- **Cross-platform**: Works on Windows, macOS, and Linux
199+
200+
The interactive mode is especially helpful when:
201+
- You're not sure of the exact target name
202+
- You want to see all available options at once
203+
- You need to quickly switch between targets
187204

188205
![slic use](docs/images/slic-use.gif)
189206

207+
#### Direct Mode (With Target Name)
208+
209+
If you already know which target you want, you can specify it directly:
210+
211+
```bash
212+
slic use the-events-calendar
213+
```
214+
215+
This immediately switches to the specified target without showing the interactive menu.
216+
217+
> For more information on this command, run `slic help use`.
218+
190219
### Initialize your project
191220

192221
With your desired plugin containing directory set, you will need to initialize plugins so that they are prepped and ready

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Changed
1010
- Breaking Change - The `slic here` command will now create a new stack for the current path instead of changing the context of the previously only stack to the path.
11-
- Breaking Change - The `XDK` configuration variable (`slic` by default) is now used as **root** for each stack IDE key. An `XDK` of `slic` will create stack IDE keys like `slic_<stack_hash>` and not just `slic` as it was before.
11+
- Breaking Change - The `XDK` configuration variable (`slic` by default) is now used as **root** for each stack IDE key. An `XDK` of `slic` will create stack IDE keys like `slic_<stack_hash>` and not just `slic` as it was before.
1212

1313
### Added
1414
- Multi-path support with a 1:1 mapping between stacks and paths.
15+
- Interactive Terminal User Interface (TUI) for the `slic use` command. Running `slic use` without arguments now opens an interactive selection menu with fuzzy search and current selection indicator.
1516
- Git worktree multi-stack support for concurrent development workflows
1617
- New `slic worktree` command with subcommands:
1718
- `slic worktree add <branch>` - Create a new git worktree with dedicated stack

slic.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ slic run wpunit
6363
```
6464

6565
Since the command might potentially run on any of the plugins maintained by the Products team, you'll need to tell the `slic` command what plugin you're currently working on with the `use` sub-command.
66-
You can change the plugin you want to run tests on by using the `slic use` command again at any moment. If you want, now to run Event Tickets tests, you could just use:
66+
67+
### Interactive Target Selection
68+
69+
The `slic use` command now provides an interactive Terminal User Interface (TUI) when called without arguments:
70+
71+
```bash
72+
slic use
73+
```
74+
75+
This opens an interactive menu that allows you to browse all available targets, see the current one, and select a new one.
76+
77+
You can also directly specify a target to skip the interactive menu:
6778

6879
```bash
6980
slic use event-tickets

src/commands/use.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
1111
USAGE:
1212
13-
<yellow>{$cli_name} {$subcommand} <target>[/<subdir>]</yellow>
13+
<yellow>{$cli_name} {$subcommand} [<target>[/<subdir>]]</yellow>
14+
15+
When called without a target argument, displays an interactive selection menu.
1416
1517
EXAMPLES:
1618
19+
<light_cyan>{$cli_name} {$subcommand}</light_cyan>
20+
Open interactive target selection menu.
21+
1722
<light_cyan>{$cli_name} {$subcommand} the-events-calendar</light_cyan>
1823
Set the use target to the-events-calendar.
1924
@@ -28,6 +33,38 @@
2833
$sub_args = args( [ 'target' ], $args( '...' ), 0 );
2934
$target = $sub_args( 'target', false );
3035

36+
// If no target provided, show TUI
37+
if ( $target === false ) {
38+
// Get all valid targets
39+
$valid_targets = get_valid_targets( true ); // true = return as array
40+
41+
if ( empty( $valid_targets ) ) {
42+
echo colorize( "<red>No valid targets found. Run 'slic here' first.</red>\n" );
43+
return 1;
44+
}
45+
46+
// Get current target (don't require it - may not be set yet)
47+
$current_target = null;
48+
$using = getenv( 'SLIC_CURRENT_PROJECT' );
49+
$using_subdir = getenv( 'SLIC_CURRENT_PROJECT_SUBDIR' );
50+
if ( ! empty( $using ) ) {
51+
$current_target = $using . ( $using_subdir ? '/' . $using_subdir : '' );
52+
}
53+
54+
// Show TUI
55+
require_once __DIR__ . '/../tui.php';
56+
$target = tui_select(
57+
$valid_targets,
58+
$current_target,
59+
'Select target (type to filter, ↑↓ to navigate, Enter to select, ESC to cancel):'
60+
);
61+
62+
// If user cancelled, exit gracefully
63+
if ( $target === null ) {
64+
return 0;
65+
}
66+
}
67+
3168
// Determine which stack to use
3269
$stack_id = slic_current_stack_or_fail( "Cannot switch target without an active stack." );
3370

0 commit comments

Comments
 (0)