2017 © Pedro PelĂĄez
 

library console

Code Inc.'s command line interface library

image

codeinc/console

Code Inc.'s command line interface library

  • Thursday, March 15, 2018
  • by joanfabregat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Console library

This PHP 7 library is providing various tools to interract with the user through a console., (*1)

Usage

Console class

The Console class allows you to interact with the user through the console., (*2)

<?php
use CodeInc\Console\Console;

// the parameter specifies if the class should throw exceptions
$console = new Console(true);

/*
 * Asks a Yes / No question and returns a boolean
 */
// returns true or false
$console->askBool("Do you like chocolate?"); 

/*
 * Asks a questions expecting a string as an answer
 */
// returns the response or null if no response is provided
echo $console->askString("What is your city?"); 

// returns the response or throws an exception if no response is provided
echo $console->askString("What is your city?", false); 

/*
 * Asks a questions with a closed list of anwsers
 */
$colors = ["green", "red", "blue", "purple", "orange", "yellow"];

// returns chosen color or throws an exception if no response is provided
echo $console->askOptions("What is your favorite color?", $colors); 

// returns chosen color or null if no response is provided
echo $console->askOptions("What is your favorite color?", $colors, true); 

CommandLine class

The CommandLine class provides simple utility static methods, (*3)

<?php
use CodeInc\Console\CommandLine;

// returns true if the script is running in CLI mode
CommandLine::isCLI(); 

// returns true if the current user is 'root'
CommandLine::isRoot(); 

// returns true if the current user is 'username'
CommandLine::isUser("username"); 

// returns the current user name or null is the user is unknow.
CommandLine::getUser();

// thow an exception if not in CLI mode
CommandLine::requireCLI(); 

// thow an exception if the current user is not 'root'
CommandLine::requireRoot(); 

// thow an exception if the current user is not 'username'
CommandLine::requireUser("username"); 

Arguments class

The Arguments class is intended to help accessing the script arguments and parameters., (*4)

<?php
use CodeInc\Console\Arguments;

// for the request 'myScript.php --param1=val1 --param2 -aDG'
$arguments = new Arguments();
$arguments->hasParameter("a"); // returns true
$arguments->hasParameter("D"); // returns true
$arguments->hasParameter("G"); // returns true
$arguments->hasParameter("z"); // returns false
$arguments->getArgumentValue("param1"); // returns 'val1'
$arguments->getArgumentValue("param2"); // returns null
$arguments->getArgumentValue("param3"); // returns false
$arguments->hasArgument("param2"); // returns true

Installation

This library is available through Packagist and can be installed using Composer:, (*5)

composer require codeinc/console

License

The library is published under the MIT license (see LICENSE file)., (*6)

The Versions

15/03 2018

dev-master

9999999-dev https://github.com/CodeIncHQ/Console

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

15/03 2018

1.2.0

1.2.0.0 https://github.com/CodeIncHQ/Console

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

15/03 2018

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/CodeIncHQ/Console

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

08/03 2018

1.1.1

1.1.1.0 https://github.com/CodeIncHQ/lib-cli

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

27/02 2018

1.1.0

1.1.0.0 https://github.com/codeinchq/lib-cli

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

20/12 2017

1.0.2

1.0.2.0 https://github.com/codeinchq/lib-cli

Code Inc.'s command line interface library

  Sources   Download

MIT

The Requires

 

19/12 2017

1.0.1

1.0.1.0 https://github.com/codeinchq/lib-cli

Code Inc.'s command line interface library

  Sources   Download

proprietary

The Requires

 

19/12 2017

1.0.0

1.0.0.0 https://github.com/codeinchq/lib-cli

Code Inc.'s command line interface library

  Sources   Download

proprietary

The Requires