| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
composer require sugarcraft/candy-shellPHP port of charmbracelet/gum — a composer-installable CLI of SugarCraft TUI primitives, useful for shell scripts.
# Apply styling.
candyshell style --foreground "#ff5f87" --bold "Hello, candy!"
# Pick one item.
choice=$(candyshell choose Pizza Burger Salad)
# Read a single line.
name=$(candyshell input --placeholder "Your name?")
# Confirm a destructive action.
candyshell confirm "Really delete $file?" && rm "$file"All 13 gum subcommands ship. Run candyshell <cmd> --help for the full flag list per command.
CandyShell uses PHP attributes to auto-discover commands at runtime. Mark any class extending Symfony\Component\Console\Command\Command with #[Command] and it will be picked up by Application::scan().
Two additional attributes enrich the --help output of your commands:
The HelpFormatter class renders these automatically when --help is invoked. It reads #[Alias] and #[Example] attributes via ReflectionClass::getAttributes() and formats them alongside the standard Symfony description and help text.
When a user types an unknown command name, Application::find() runs it through a TypoSuggester that computes Levenshtein distance against all registered command names. If a match is found within distance ≤ 2, the error message suggests the nearest alternative (e.g. "Did you mean choose?"). Beyond distance 2 the original error propagates silently.
use SugarCraft\Shell\Attribute\Command;
use SugarCraft\Shell\Attribute\Flag;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[Command(name: 'mycmd', description: 'Does something useful.', descriptionSection: 'Longer help text.')]
final class MyCommand extends Command
{
#[Flag(name: 'format', short: 'f', description: 'Output format.', enum: FormatType::class)]
protected function configure(): void
{
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$format = $input->getOption('format');
// ...
return self::SUCCESS;
}
}
enum FormatType: string
{
case Json = 'json';
case Yaml = 'yaml';
}Register the namespace in your bootstrap:
$app = new \SugarCraft\Shell\Application();
$app->scan('My\\Namespace\\'); // discovers all #[Command] classes
$app->run();Application::scan($namespace) iterates all already-loaded classes under that namespace, picks those bearing #[Command], and registers them into the application. Classes must be autoloaded (or required) before scan() can find them — the scanner uses get_declared_classes() and does not trigger autoloading.
| Command | Role |
|---|---|
| choose | Pick one or many items from a list. |
| completion | Emit shell completion script (bash · zsh · fish). |
| confirm | Yes/no prompt — exit 0 on confirm, 1 on cancel. |
| file | Interactive file picker. |
| filter | Fuzzy filter over stdin lines (single- or multi-select). |
| format | Render Markdown / code / template / emoji to the terminal. |
| input | Read a single line; supports --password masking. |
| join | Concatenate two styled fragments side-by-side or stacked. |
| log | Levelled / structured log output (text · json · logfmt). |
| pager | Scrollable viewer for long input. |
| spin | Run an external command behind a spinner. |
| style | Apply Sprinkles styling to argv (or stdin). |
| table | Render a CSV / TSV table. |
| write | Multi-line text editor. |
The audit lists upstream-gum flags that are not yet wired in CandyShell. The shipped surface today covers the 80 % case for shell scripts; see AUDIT_2026_05_06.md for the full delta. Common flags across commands:
CandyShell respects standard CLI colour conventions:
Any command option can be given via an environment variable using the CANDYSHELL_ prefix followed by the option name in uppercase with non-alphanumeric characters replaced by _. For example:
# Equivalent to: candyshell style --foreground=#ff0000 --bold "Hello"
CANDYSHELL_FOREGROUND=#ff0000 CANDYSHELL_BOLD=1 candyshell style "Hello"The fallback is applied when no explicit CLI option is provided. An explicit flag on the command line always takes precedence over the env var.
candyshell completion --shell=bash
candyshell completion --shell=zsh
candyshell completion --shell=fishEmit a shell completion script for bash, zsh, or fish. Source the output directly or drop it into the appropriate completion directory.
candyshell --version reports the version read from the monorepo root composer.json via Application::versionFromComposer(). The version is discovered by walking up from the package directory to find the nearest composer.json with a non-empty version field.
Most gum X invocations work as candyshell X verbatim. Known behavioural differences (also see AUDIT_2026_05_06.md):
cd candy-shell && composer install && vendor/bin/phpunitThe filter command uses candy-fuzzy for fuzzy-matching via FilterModel → SmithWatermanMatcher. The shell-style flag parser (SubStyleParser) operates on style-flag strings in isolation and has no fuzzy logic.
| Back | FazBrowse Home | New Git URL |