Download the PHP package tolidano/commandox without Composer

On this page you can find all versions of the php package tolidano/commandox. 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 commandox

CommandoX

PHP 7.2+ CLI Manager

Build Status

CommandoX is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for command line use. This is a PHP 7.2+ port of Nate Good's abandoned Commando project available here: (https://www.github.com/nategood/commando)

Why?

PHP's $argv magic variable and global $_SERVER['argv'] should be avoided, encapsulated, or abstracted away in proper OOP design. PHP's getopt is not a significant improvement, and most other PHP CLI libraries are far too OOP bloated. CommandoX provides a clean and readable interface without a ton of overhead or common boilerplate when it comes to handling CLI input.

Installation

CommandoX requires that you are running PHP 7.2 or higher.

CommandoX is PSR-0 compliant and can be installed using Composer. Add tolidano/commandox to your composer.json

"require": {
    "tolidano/commandox": "*"
}

If you're new to Composer...

Installing via Composer is the only supported option.

Example

Here is an example of a PHP CommandoX script that gives a decent tour of CommandoX's features:

Running it (save the above script to hello.php):

> php hello.php Shawn
Hello, Shawn!

> php hello.php --capitalize shawn
Hello, Shawn!

> php hello.php -c -t Mr 'shawn tolidano'
Hello, Mr. Shawn Tolidano!

> php hello.php -ceet Mr 'shawn tolidano'
Hello, Mr. Shawn Tolidano Esq.!

Things to note:

Automatic Help

CommandoX has automatic -h/--help support built in. Calling your script with this flag (either -h or --help) will print out a help page based on your option definitions and CommandoX settings. If you define an option with the name or alias of h or help, it will override this built in support.

help screenshot

Error Messaging

By default, CommandoX will catch Exceptions that occur during the parsing process. Instead, CommandoX prints a formatted, user-friendly error message to standard error and exits with a code of 1. If you wish to have CommandoX throw Exceptions instead, call the doNotTrapErrors method on your Command instance.

error screenshot

Command Methods

These options work on the "command" level.

useDefaultHelp (bool help)

The default behavior of CommandoX is to provide a --help option that spits out a useful help page generated off of your option definitions. Disable this feature by calling useDefaultHelp(false)

setHelp (string help)

Text to prepend to the help page. Use this to describe the command at a high level and provide some examples usages of the command.

printHelp()

Print the default help for the command. Useful if you want to output help if no arguments are passed.

beepOnError (bool beep=true)

When an error occurs, print character to make the terminal "beep".

getOptions

Return an array of Options for each option provided to the command.

getFlags

Return an array of Options for only the flags provided to the command.

getArguments

Return an array of Options for only the arguments provided to the command. The order of the array is the same as the order of the arguments.

getFlagValues

Return associative array of values for arguments provided to the command. E.g. ['f' => 'value1'].

getArgumentValues

Return array of values for arguments provided to the command. E.g. ['value1', 'value2'].

Command Option Definition Methods

These options work on the "option" level, even though they are chained to a Command instance

option (mixed $name = null)

Aliases: o

Define a new option. When name is set, the option will be a named "flag" option. Can be a short form option (e.g. f for option -f) or long form (e.g. foo for option --foo). When no name is defined, the option is an anonymous argument and is referenced by its ordinal position.

flag (string $name)

Same as option except that it can only be used to define "flag" type options (aka those options that must be specified with a -flag on the command line).

argument ()

Same as option except that it can only be used to define "argument" type options (aka those options that are specified WITHOUT a -flag on the command line).

alias (string $alias)

Aliases: a, aka

Add an alias for a named option. This method can be called multiple times to add multiple aliases.

description (string $description)

Aliases: d, describe, describedAs

Text to describe this option. This text will be used to build the "help" page.

require (bool $require)

Aliases: r, required

Require that this flag is specified.

needs (string|array $options)

Aliases: none

Require that other $options be set for this option to be used.

must (Closure $rule)

Aliases: none

Define a rule to validate input against. Takes function that accepts a string $value and returns a boolean as to whether or not $value is valid.

map (Closure $map)

Aliases: cast, castTo

Perform a map operation on the value for this option. Takes function that accepts a string $value and returns mixed (map to any type).

referToAs (string $name)

Aliases: title, referredToAs

Add a name to refer to an argument option by. Makes help and error messages cleaner for anonymous "argument" options.

boolean ()

Aliases: none

Specifices that the flag is a boolean type flag.

increment (int $max)

Aliases: i, count, repeats, repeatable

Specifies that the flag is a counter flag. The value of the flag will be incremented up to the value of $max for each time the flag is used in the command. Options that are set to increment or boolean types can be grouped together as a single option.

default (mixed $defaultValue)

Aliases: defaultsTo

If the value is not specified, default to $defaultValue.

In the specific case of boolean() flags, when the flag is present, the value of this option is the negation of $defaultValue. That is to say, if you have a flag -b with a default of true, when -b is present, the value of the option will be false.

file ()

Aliases: expectsFile

The value specified for this option must be a valid file path. When used, relative paths will be converted into fully-qualified file paths and globbing is also optionally supported. See the file.php example.

Contributing

CommandoX encourages pull requests. When submitting a pull request:

Inspiration / Original

Released under MIT license.

Change Log

v0.7.2 (Multiple Breaking Changes)

v0.5.4 (Multiple Breaking Changes)

v0.2.9

v0.2.8

v0.2.7

v0.2.6

v0.2.5

v0.2.4

v0.2.3

v0.2.2

v0.2.1

v0.2.0

The primary goal of this update was to better delineate between flag options and argument options. In Commando, flags are options that we define that require a name when they are being specified on the command line. Arguments are options that are not named in this way. In the example below, '-f' and '--long' are described as "flags" type options in Commando terms with the values 'value1' and 'value2' respectively, whereas value3, value4, and value5 are described as "argument" type options.

v0.1.4

v0.1.3

v0.1.2


All versions of commandox with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
kevinlebrun/colors.php Version 1.0.*
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 tolidano/commandox contains the following files

Loading the files please wait ....