Download the PHP package eftec/clione without Composer

On this page you can find all versions of the php package eftec/clione. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package clione

CliOne

This library helps to create command line (CLI) operator for PHP in Windows, Mac and Linux

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

Features

✅ Windows, Linux and Mac Compatible.

✅ This library truly minimalist and simple, it only consists of 2 classes and nothing more and no external dependency.

✅ Arguments & user input

✅ This library was aimed to (optionally) fallback to user-input if the argument is missing.

✅ Colors available

✅ The design is mostly fluent (it adjusts to the width of the screen)

✅ Validation of values

✅ Support NO_COLOR environment variable. See https://no-color.org/

Getting started

Add the library using composer:

composer require eftec/clione

And create a new instance of the library

Usage

For example, let's say we need to create a CLI code to read an information and save into a file.

We have two arguments, the first (read) is in the first position, and it doesn't have any "-". The second is "-o" that it is our flag with a value.

So we could create our arguments.

And we could evaluate as

It will return false if we don't set a value, and it will return the value it we set it.

The parameters are created and evaluated separately because it allows to do more powerful operations with it.

For example, sometimes we want to show the help (the list of parameters available) without evaluating the parameters.

Ok, but now what if we want to create an alias of "-o"

So we could call using this line

If the parameter is a flag, then the alias is a longflag ("--"). If the parameter is a longflag then the alias is a flag.

But let's say we need to ask for a password, however we want to be entered interactively.

So it will look like:

Now, let's say something more advanced, multiple options, we want to select the type of file: json, csv, html and xml

Our code

And the result:

List of values are divided in two values, the visual value (simply called value), and the key-value.. In this example, "csv" is a value and its key-value is "2".

The list of values allows associative arrays and indexed arrays. Indexed arrays are renumbered to start in 1.

You could also enter

php .\basic.php read -o result.json -pwd 123 -type json

Now, you can show the parameters ("show the syntax help") as follows:

But it will look plain.

It is because you can add a description, change the question and add more help information

So it will look like: (in colors)

There are more operations available but the basic is there.

Table of contents

Flow

Note:

Input as arguments

The system allows reading multiple types of arguments

The argument could be created as:

And it could be read as:

Now, what if you want to create multiples alias for the same parameter.

Input interactive

There are several configuration to set an input interactively.

By default, every parameter is read as argument. If the value is read as argument, then it is not asked interactively.

However, if the parameter is of the type "none" or "onlyinput", then they are only obtained by user input ( interactively).

Example:

User input (interactive)

With the method setInput() we set that this parameter could also be read interactively.

Example, let's say the next example:

Now, this input accepts any kind of text. But there is many kind of user input.

type description argument example
number It allows any kind of number setInput(true,"number")
range it only allow number between a range of values [1,20] setInput(true,"range",[1,10])
string It allows any type of value (used for auto complete) setInput(true,"string")
password It allows any type of value but the default value is never displayed setInput(true,"password")
multiple it allows to check one or multiple values using 1 column ['key1'=>'value1','key2'=>'value2'] setInput(true,"multiple",['key1'=>'value1','key2'=>'value2'])
multiple2 it allows to check one or multiple values using 2 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"multiple2",['key1'=>'value1','key2'=>'value2'])
multiple3 it allows to check one or multiple values using 3 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"multiple3",['key1'=>'value1','key2'=>'value2'])
multiple4 it allows to check one or multiple values using 4 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"multiple4",['key1'=>'value1','key2'=>'value2'])
option it allows to select a value from a list using 1 column ['key1'=>'value1','key2'=>'value2'] setInput(true,"option",['key1'=>'value1','key2'=>'value2'])
option2 it allows to select a value from a list using 2 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"option2",['key1'=>'value1','key2'=>'value2'])
option3 it allows to select a value from a list using 3 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"option3",['key1'=>'value1','key2'=>'value2'])
option4 it allows to select a value from a list using 4 columns ['key1'=>'value1','key2'=>'value2'] setInput(true,"option4",['key1'=>'value1','key2'=>'value2'])
optionshort It allows a selection of values ["yes","no"] setInput(true,"multiple4",['key1'=>'value1','key2'=>'value2'])

Option returns a value and a value-key. Value is the content visible. And value-key, is the content selected by the user.

Example Option:

Example Multiple:

Customize user input

It is possible to customize the input by changing the help description, changing the question, showing an example or showing a value to the argument

CliOne Class

CliOne - A simple creator of command-line argument program.

Method __construct()

The constructor. If there is an instance, then it replaces the instance.

Parameters:

Method getWindowsVersion()

It returns the current Windows version as a decimal number.
If no version is found then it returns 6.1 (Windows 7).
Windows 10 and Windows 11 versions are returned as 10.xxxx instead of 10.0.xxxx

Method instance()

It gets the current instance of the library.
If the instance does not exist, then it is created

Parameters:

Method hasInstance()

Returns true if there is an instance of CliOne.

Method hasMenu()

It returns true if CliOne has a menu defined. It will return false if there is no menu or there is no instance.

Method clearMenu()

It clears a menu and the services associated.

Parameters:

Method addMenu()

It adds a new menu that could be called by evalMenu()
Example:

Parameters:

Method addMenuItem()

It adds a menu item.
Example:

Parameters:

Method addMenuItems()

It adds multiples items to a menu
Example:

Parameters:

Method addMenuService()

It adds a service object to be evaluated when we run evalMenu()
You can add menu services. Every service is evaluated in order, so if both service objects has the same method, then it is only called by the first object.
If evalMenu() uses a service then, the services defined here are ignored.
Example:

Parameters:

Method evalMenu()

Eval (executes) a menu previously defined.
Example:

Parameters:

Method getErrorType()

Method getMemory()

Method setVariable()

It sets a value into an array.

Parameters:

Method getVariable()

It gets the value of a variable

Parameters:

Method addVariableCallBack()

It adds a callback function.
Example:

This function is called every setVariable() if the value is different as the defined.

Parameters:

Method callVariablesCallBack()

It calls the callback functions. Usually they are called every time we setVariable() (and the value is changed).

Method hasColorSupport()

This function is based in Symfony

Method testArguments()

It is used for testing. You can simulate arguments using this function
This function must be called before the creation of the instance

Parameters:

Method testUserInput()

It is used for testing. You can simulate user-input using this function
This function must be called before every interactivity
This function is not resetted automatically, to reset it, set $userInput=null

Parameters:

Method setMemory()

It sets the value stored into the memory stream
If the memory stream has values, then they are deleted and replaced.

Parameters:

Method setErrorType()

It sets if you want to display errors or not. This flag is reseted every time it is used.

Parameters:

Method findVendorPath()

It finds the vendor path starting from a route. The route must be inside the application path.

Parameters:

Method createParam()

It creates a new parameter to be read from the command line and/or to be input manually by the user
Example:

Parameters:

Method createOrReplaceParam()

Method downLevel()

Down a level in the breadcrub.
If down more than the number of levels available, then it clears the stack.

Parameters:

Method evalParam()

It evaluates the parameters obtained from the syntax of the command.
The parameters must be defined before call this method
Example:

Parameters:

Method throwError()

It throws an error. Depending on the type, it could show an error or throw a runtime exception.

Parameters:

Method showWarning()

It shows a warning

Parameters:

Method addHistory()

Add a value to the history

Parameters:

Method setHistory()

It sets the history (deleting the old history) with the new values

Parameters:

Method clearHistory()

It clears the global history (if any).

Method listHistory()

It retrieves the global history (if any)

Method getArrayParams()

It returns an associative array with all the parameters of the form [key=>value]
Parameters of the type "none" are ignored

Parameters:

Method getColSize()

It returns the number of columns present on the screen. The columns are calculated in the constructor.

Method getParameter()

It gets the parameter by the key or an empty parameter with a null key if null.

Parameters:

Method getValue()

It reads a value of a parameter. Example:

Parameters:

Method readArgument()

It reads a parameter as an argument or flag.

Parameters:

Method showHelp()

It shows the help

Parameters:

Method makeBigWords()

Parameters:

Method getValueKey()

It reads the value-key of a parameter selected. It is useful for a list of elements.
Example:

Parameters:

Method isCli()

It will return true if the PHP is running on CLI
If the constructor specified a file, then it is also used for validation. Example:

Method getSTDIN()

It gets the STDIN exclusively if the value is passed by pipes. If not, it returns null;

Method readData()

It reads information from a file. The information will be de-serialized.

Parameters:

Method readDataPHPFormat()

It reads information from a file. The information is evaluated, so the file must be safe.

Parameters:

Method isParameterPresent()

Returns true if the parameter is present with or without data.
The parameter is not changed, neither the default values nor user input are applied
Returned Values:

Parameters:

Method addExtensionFile()

Util class. It adds a default extension to a filename only if the filename doesn't have extension.

Parameters:

Method saveData()

It saves the information into a file. The content will be serialized.

Parameters:

Method saveDataPHPFormat()

It saves the information into a file. The content will be converted into a PHP file.
Example:

Parameters:

Method setAlign()

It sets the alignment. This method is stackable.
Example:

Parameters:

Method setArrayParam()

It sets the parameters using an array of the form [key=>value]
It also marks the parameters as missing=false

Parameters:

Method reconstructPath()

It is used internally to reconstruct the path of the current script.

Parameters:

Method getPhpOriginalFile()

It gets the php original file

Method setPhpOriginalFile()

It sets the php original file

Parameters:

Method setColor()

It sets the color in the stack

Parameters:

Method setParam()

It sets the value or value-key of a parameter manually.
It also marks the origin of the argument as "set" and it markes the argument as missing=false

Parameters:

Method setParamUsingArray()

Set the values of the parameters using an array.
If the parameter does not exist, then it is created with the default values

Parameters:

Method createContainer()

USE FUTURE. It creates a container.

Parameters:

Method getValueAsArray()

It gets the values of the parameters are an associative array.

Parameters:

Method setPatternTitle()

It sets the pattern used for the title. This operation is used in a stack. {value} {type}

Parameters:

Method setPatternCurrent()

{value}{type}

Parameters:

Method setPatternSeparator()

">"

Parameters:

Method setPatternContent()

Not used yet.

Parameters:

Method setStyle()

It sets the styles used by different elements

Parameters:

Method show()

It's similar to showLine, but it keeps in the current line.

Parameters:

Method showBread()

It shows a breadcrumb.
To add values you could use the method uplevel()
To remove a value (going down a level) you could use the method downlevel()
You can also change the style using setPattern1(),setPattern2(),setPattern3()

It shows the current BreadCrumb if any.

Parameters:

Method showCheck()

It shows a label messages in a single line, example: [ERROR] Error message

Parameters:

Method showFrame()

It shows a border frame.

Parameters:

Method showLine()

It shows (echo) a colored line. The syntax of the color is similar to html as follows:
Example:

Parameters:

Method clearScreen()

It clears the current screen
Example:

Method cursorHome()

It sets the cursor to the top left position
Example:

Method cursorMove()

It moves the cursor at some specific position
Example:

Parameters:

Method bell()

Method getCursorPosition()

It gets the current position of the cursor

It requires getCh() executable up and configured in Windows Example:

Method showMessageBox()

It shows a message box consisting of two columns.

Parameters:

Method alignLinesVertically()

Parameters:

Method maxWidth()

Method showParamSyntax()

It shows the syntax of a parameter.

Parameters:

Method showParamSyntax2()

It shows the syntax of the parameters.

Parameters:

Method setDefaultStream()

Parameters:

Method setNoColor()

Parameters:

Method isNoColor()

Method setNoANSI()

if true then the console is in old-cmd mode (no colors, no utf-8 characters, etc.)

Parameters:

Method isNoANSI()

returns true if the

Method wrapLine()

it wraps a line and returns one or multiples lines
The lines wrapped does not open or close tags.

Parameters:

Method showProgressBar()

Parameters:

Method getPageSize()

it gets the size of the page (number of rows) to display in a table

Method showTable()

It shows an associative array. This command is the end of a stack.

Parameters:

Method showValuesColumn()

It shows the values as columns.

Parameters:

Method showWaitCursor()

It shows a waiting cursor.
Example:

Parameters:

Method hideWaitCursor()

Method hideCursor()

Method showCursor()

Method showparams()

It will show all the parameters by showing the key, the default value and the value
It is used for debugging and testing.

Method showParamValue()

Parameters:

Method strlen()

It determines the size of a string

Parameters:

Method removechar()

remove visible characters at the end of the string. It ignores invisible (such as colors) characters.

Parameters:

Method upLevel()

Up a level in the breadcrumb

Parameters:

Method getCh()

It reads an input character. It does not work with special characters
This function is basic, it does not work with all keystrokes, and it could be CPU intensive (for a loop)

In Windows, it uses the getch.exe in any path folder (or you can set the path with $this->getChWinExe).
You can download from here https://github.com/escuelainformatica/getch/releases Example:

Parameters:

Method colorText()

It sets the color of the cli

Parameters:

Method colorLess()

It removes all the escape characters of a content

Parameters:

Method colorMask()

It masks (with a char 250) all the escape characters.

Parameters:

Method initialEndStyle()

It returns the initial and end style of a text.
If the text only contains an initial or final style, then nothing is returned

Parameters:

Method replaceCurlyVariable()

Replaces all variables defined between {{ }} by a variable inside the dictionary of values.
Example:

Parameters:

menu

You can create a menu using the next methods

addMenu()

It creates a new menu

addMenuItem()

It adds an option to a menu

addMenuItems()

It adds multiple options to a menu

evalMenu()

It executes a menu

clearMenu()

It clears a menu.

example

Examples

Example using arguments

example/example1.php

And create the next code

So you can run as:

Example using user input

You can ask for user input of the user.

example/example2.php

It will show the next result

Example with a game

example/examplegame.php

Image (c) George Beker

Example colors

You can see the tags available in Types of colors

example/examplecolor.php

Example tables

example/exampletables.php

Types of user input

userinput description
number the value must be a number
range the value must be a number between a range of values
string the value must be a string (by default, nulls are not string)
password the value must be a string (and if it is displayed, then it shows ****)
multiple It allows to select one or many values displated in 1 column
multiple2 The same than multiple but displayed in 2 columns
multiple3 The same than multiple but displayed in 3 columns
multiple4 The same than multiple but displayed in 4 columns
option It allows to select one from many values displayed in a column
option2 The same than option but displayed in 2 columns
option3 The same than option but displayed in 3 columns
option4 The same than option but displayed in 4 columns
optionsimple It allows to select one from many values. It doesn't use columns

Types of colors

tag description
error color red
warning color yellow
information blue
black black
white white
success color green
italic italic
bold bold
underline underline
cyan color light cyan
magenta color magenta
col0 leftmost column
if the input has some options
red background color red
.. background color

Definitions

You can find the definition of the classes, methods and fields at:

definitions.md

debug

To activate the debug mode, you must set the debug field as true:

In debug mode, every user input is recored in the field $debugHistory

You can also see the history running the input ??history

And you can clear the history using the input ??clear

The goal is we could store a session and replace it using testUserInput()

You can also load and save the user input

Compatibility

Changelog


All versions of clione with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-readline Version *
ext-json Version *
ext-iconv Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package eftec/clione contains the following files

Loading the files please wait ....