Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation to prompt #808

Merged
merged 6 commits into from
Nov 1, 2017

Conversation

natanfelles
Copy link
Contributor

Usage example:

<?php namespace App\Commands;

use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\BaseCommand;

class UsersCreate extends BaseCommand
{
	protected $group       = 'Users';
	protected $name        = 'users:create';
	protected $description = 'Create user.';

	public function run(array $params)
	{
		// Title
		CLI::write('Users Create', 'yellow');

		// Inputs
		$name = CLI::prompt('Name', null, 'required|min_length[4]|max_length[32]');
		$email = CLI::prompt('Email', null, 'required|valid_email');
		$state = CLI::prompt('State', 'rs', 'in_list[rs,sc,pr]');
		$city = CLI::prompt('City', ['Porto Alegre','Florianópolis','Curitiba'], 'required');

		CLI::newLine();

		// Title
		CLI::write('User Data to be Registered', 'light_green');

		// Outputs
		CLI::write('Name: ' . $name);
		CLI::write('Email: ' . $email);
		CLI::write('State: ' . $state);
		CLI::write('City: ' . $city);

		CLI::newLine();

		// Call a Model...
	}

}

@lonnieezell
Copy link
Member

Looks great. Thanks!

@lonnieezell lonnieezell merged commit 4d8b6e1 into codeigniter4:develop Nov 1, 2017
@natanfelles natanfelles deleted the prompt_validate branch November 15, 2017 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants