theroadbunch/command-menu

A simple class for command menus

v1.0.0 2019-01-07 19:56 UTC

This package is auto-updated.

Last update: 2024-05-08 08:20:53 UTC


README

A simple menu for symfony console commands

Latest Stable Version License: MIT Compatible Symfony Version

a quick note:
This README assumes you have an understanding of creating and running a console command in the symfony ecosystem

Contents

  1. Release Notes
  2. Installation
  3. Usage
    a. Basic Usage
    b. Selectors
    c. Wrappers
  4. License

Install using composer [?]

composer require theroadbunch/command-menu

Basic Usage

Creating, rendering, and using a menu in your symfony console command

<?php

// ...
use RoadBunch\CommandMenu\Menu;
use RoadBunch\CommandMenu\Option;

// ...

public function execute(InputInterface $input, OutputInterface $output)
{      
    // create the menu
    $menu = new Menu($input, $output);
    
    // optional title
    $menu->title('Options');
    
    // add options
    $menu->addOption('add', 'Add User');
    $menu->addOption('delete', 'Delete User');
    $menu->addOption('quit', 'Quit');
    
    // render the menu
    $menu->render();
        
    // prompt the user to make a selection
    $selection = $menu->promptForSelection();
    
    // do work
}

Output

Options
-------

1 Add User
2 Delete User
3 Quit

Please make a selection:
> |

If the user selects 1 then promptForSelection() will return "add", 2 will return "delete", and 3 will return "quit"
In the event a user selects something other than a given selector, promptForSelection() will return null