GithubHelp home page GithubHelp logo

shomisha / laravel-console-wizard Goto Github PK

View Code? Open in Web Editor NEW
132.0 4.0 3.0 90 KB

Laravel Console Wizard is a library for creating multi-step wizards using Laravel's Artisan CLI tool.

License: MIT License

PHP 100.00%

laravel-console-wizard's Introduction

Laravel Console Wizard

Latest Stable Version Software License

This package provides a basis for creating multi-step wizards with complex input inside the console. It is best used for customising generator command output, but can be used for handling any sort of tasks.

<?php

namespace App\Console\Commands;

use Shomisha\LaravelConsoleWizard\Command\Wizard;
use Shomisha\LaravelConsoleWizard\Steps\ChoiceStep;
use Shomisha\LaravelConsoleWizard\Steps\TextStep;

class IntroductionWizard extends Wizard
{
    protected $signature = "wizard:introduction";

    protected $description = 'Introduction wizard.';

    public function getSteps(): array
    {
        return [
            'name'   => new TextStep("What's your name?"),
            'age'    => new TextStep("How old are you?"),
            'gender' => new ChoiceStep("Your gender?", ["Male", "Female"]),
        ];
    }

    public function completed()
    {
        $this->line(sprintf(
            "This is %s and %s is %s years old.",
            $this->answers->get('name'),
            ($this->answers->get('gender') === 'Male') ? 'he' : 'she',
            $this->answers->get('age')
        ));
    }
}

The example above shows a simple example of how you can create a wizard with several input prompts and then perform actions using the answers provided by the user. Running php artisan wizard:introduction in your console would execute the above wizard and produce the following output:

shomisha:laravel-console-wizard shomisha$ php artisan wizard:introduction

 What's your name?:
 > Misa

 How old are you?:
 > 25

 Your gender?:
  [0] Male
  [1] Female
 > 0

This is Misa and he is 25 years old.

Take a look at our wiki pages for more instructions and other Wizard features.

laravel-console-wizard's People

Contributors

shomisha avatar laravel-shift avatar

Stargazers

dc avatar Kalpesh Gamit avatar  avatar  avatar Joseph Harris avatar Habib Talib avatar Justany ITOUA avatar Vasu Grover avatar Damian Chojnacki avatar Miguel Enes avatar Michele Di Brigida avatar Akshay Jumbade avatar Houari Belhati avatar Pietro Iglio avatar Carlos Trindade avatar Michael Bryne avatar Joey Harris avatar Milad avatar caizhigang avatar Bill Condo avatar  avatar wilbur.yu avatar Kevin Krieger avatar Peter Jaap Blaakmeer avatar Marc Reichel avatar Wes Hulette avatar Abel avatar Nikolas Evers avatar Christian Quispe H avatar Alessandro Benoit avatar Pavel avatar Teddy Jimenez avatar Lúdio Oliveira avatar Carlos Augusto Gartner avatar Ruben Robles avatar Martijn Dorsman avatar bhu Boue vidya avatar  avatar Ally Dewar avatar Subraga Islammada S avatar Denny avatar Roger Mathews Arruda avatar Roberto Gallea avatar Justin W avatar Fabrice Yopa avatar HDVinnie avatar Humberto Pereira avatar محمود عبدالسميع التوم avatar Alexandre Almeida avatar Ventsislav Radev avatar Arif Widipratomo avatar MarcS avatar Anders Jürisoo avatar  avatar Kodjo Edem avatar Brian Lee avatar Khairudi avatar Olivier Mourlevat avatar William Whitmire avatar Wanderley Ferreira de Albuquerque avatar Rafael Laurindo avatar cooltheo avatar fabrizio avatar Andrew Pikulik avatar lonquan avatar Patompong Savaengsuk avatar Dinçer Demircioğlu avatar Mohammad Prince avatar Mark avatar Frank Mwangi avatar Charlie Page avatar François M. avatar Lucas Yang avatar  avatar Alpha Olomi avatar Leonardo Hipolito avatar  avatar Soysal Tan avatar Haider Ali avatar Julian Vogin avatar Stephen Jude avatar Kevyworks avatar Lenix avatar Daniel Hartmann avatar Alexey avatar Tom Zajac avatar ketsakda avatar Manuel Pirker-Ihl avatar Andrew G. avatar Fatih Toprak avatar Martin Trubelik avatar Gilson Gabriel avatar Diaa Fares avatar Jean-François De Las Heras avatar Sheldon Rupp avatar Dusan Malusev avatar Stefan Bogdanović avatar Braunson Yager avatar Matija Boban avatar TiX avatar

Watchers

James Cloos avatar Miguel Enes avatar  avatar  avatar

laravel-console-wizard's Issues

Using In a Package

Hey there, this is a great package. I'm attempting to include it in a package I have that has a ton of generators, but it doesn't seem to be finding the classes.

I noticed the ServiceProvider only provides the GenerateWizardWizard command so I skipped loading that and just loaded that command into my GeneratorServiceProvider.

It works fine from inside a Laravel app via a generated console command, but when I call a command from my package I get an error that the $answer property doesn't exist:

Undefined property: MyPackage\Console\Commands\ScaffoldMakeCommand::$answer

Very strange, the steps work fine, it loads, asks all the questions perfectly, then blows up.

Any ideas?

why not support 7.3 with polyfill?

Still many people use php 7.3 as that is the laravel's required version,
so it would be better if you can support php7.3 using polyfill

thanks.

Feature request: skip step if argument is provided

I very often use trait like this in my projects

<?php

namespace App\Console\Traits;

trait ArgumentOrAsk
{

    public function argumentOrAsk($name, $question = null, $default = null)
    {
        $argument = $this->argument($name);

        if (!empty($argument)) {
            return $argument;
        }

        return $this->ask($question ?? $name, $default);
    }
}

and I think it would be great if step could read value from arguments and maybe even ask that value again if validation rules fail

Generator Wizard Options

Okay, I have a genuine issue now that I'd like to figure out how to resolve.

All of the wizards in my package will be generators. So I've discovered I need to extend the GeneratorWizard class for this. Most of them will work fine as is since they are creating a named file. But I have a couple that don't create an actual class, they just call other generator commands.

For instance my ScaffoldMakeCommand I referenced in that previous issue. I moved the the first step into the getNameStep which works as expected, then moved my build calls from completed into generateTarget and those all run and generate all the files as expected.

The one exception here is that an extra empty file is created based on the input from getNameStep.

For example, here is my getNameStep:

public function getNameStep(): Step
{
  return new TextStep('What namespace would you like to create?');
}

This sets a namespace to then generate a bunch of files within that directory. So let's say I want to create a Countries namespace.

I go through the wizard answering all the steps:

public function getSteps(): array
{
  return [
    'visibility' => new ChoiceStep('What visibility should the namespace have?', [
      'Public', 'Protected', 'Private', 'API',
    ]),
    'actions' => new UniqueMultipleChoiceStep('Select all the actions to create for your namespace', [
      'Index', 'Create', 'Show', 'Store', 'Edit', 'Update', 'Delete', 'Restore', 'Destroy',
    ], [
      'end_keyword' => 'done',
      'retain_end_keyword' => false,
    ]),
    'model' => new TextStep('Enter the name of the Model to use for this namespace'),
    'repository' => new ConfirmStep('Would you like a repository?'),
    'observer' => new ConfirmStep('Do you need an Observer?'),
  ];
}

Then all the files requested are created, and at the end I get an empty file at:

app/Countries.php

Is there a way I can stop this file from being created? In my previous command which just extended GeneratorCommand this did not get created because I left the getStub method empty. I did that here too but it still gets created, I'm guessing maybe from the parent::handle() call in GeneratorWizard?

Any thoughts would be helpful.

Thanks again for the great package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.