Download the PHP package bobdenotter/commando without Composer

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

Commando

Note: This is a fork of https://github.com/nategood/commando, compatible with PHP 8.1 and up.

An Elegant PHP CLI Library

Commando is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for command line use.

Why?

PHP's $argv magic variable and global $_SERVER['argv'] make me cringe, getopt isn't all that much better, and most other PHP CLI libraries are far too bloated for many cases. Commando gets down to business without a ton of overhead, removes the common boilerplate stuff when it comes to handling CLI input, all while providing a clean and readable interface.

Installation

Commando requires that you are running PHP 8.1 or higher.

Commando is PSR-0 compliant and can be installed using Composer. Add bobdenotter/commando to your composer.json

"require": {
    "bobdenotter/commando": "*"
}

If you're new to Composer...

Currently installing via Composer is the only supported option.

Example

Here is an example of a PHP Commando script that gives a decent tour of Commando's features. Let's say it is in a file called hello.php.

Running it:

> php hello.php Nate
Hello, Nate!

> php hello.php --capitalize nate
Hello, Nate!

> php hello.php -c -t Mr 'nate good'
Hello, Mr. Nate Good!

> php hello.php -ceet Mr 'nate good'
Hello, Mr. Nate Good esq!

Things to note:

Baked in Help

Commando has automatic --help support built in. Calling your script with this flag will print out a pretty help page based on your option definitions and Commando settings. If you define an option with the alias of 'help', it will override this built in support.

help screenshot

Error Messaging

By default, Commando will catch Exceptions that occur during the parsing process. Instead, Commando prints a formatted, user-friendly error message to standard error and exits with a code of 1. If you wish to have Commando throw Exceptions in these cases, 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 Commando 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 maybe 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 options 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. array('f' => 'value1').

getArgumentValues

Return array of values for arguments provided to the command. E.g. array('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 in the future by its position.

flag (string $name)

Same as option except that it can only be used to define "flag" type options (a.k.a. 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 (a.k.a 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 and as such, it is end user facing.

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: N/A

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 return mixed (you can map to whatever you wish).

reduce (Closure $reducer [, mixed $seed])

Aliases: list, each, every

Execute an accumulator/reducer function on every instance of the option in the command. Takes an accumulator function, and returns mixed (you can return any value). If you also supply a map for the option the map will execute on every value before it is passed to the accumulator function. If $seed value is supplied, this will be used as the default value.

Signature: function(mixed $accumulated, mixed $value) : mixed

referToAs (string $name)

Aliases: title, referredToAs

Add a name to refer to an argument option by. Makes the help docs a little cleaner for anonymous "argument" options.

boolean ()

Aliases: N/A

Specifices that the flag is a boolean type flag.

increment (int $max)

Aliases: i, count, repeats, repeatable

Specifies that the flag is a counter type 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.

default (mixed $defaultValue)

Aliases: defaultsTo

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

In the case of boolean() type flags, when the flag is present, the value of this option the negation of $defaultValue. That is to say, if you have a flag -b with a default of true, when -b is present as a command line flag, 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 quantify file paths and globbing is also optionally supported. See the file.php example.

boolean ()

Aliases: N/A

Specifices that the flag is a boolean type flag.

default (mixed $defaultValue)

Aliases: defaultsTo

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

In the case of boolean() type flags, when the flag is present, the value of this option the negation of $defaultValue. That is to say, if you have a flag -b with a default of true, when -b is present as a command line flag, 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 quatified file paths and globbing is also optionally supported. See the file.php example.

Contributing

Commando highly encourages sending in pull requests. When submitting a pull request please:

Inspiration

Released under MIT license.

Change Log

1.0.0

v0.4.0

v0.3.0

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 commando with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
kevinlebrun/colors.php Version ^0.4
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 bobdenotter/commando contains the following files

Loading the files please wait ....