Download the PHP package nette/command-line without Composer

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

Nette Command-Line

Downloads this Month Tests Coverage Status Latest Stable Version License

A lightweight library for building command-line applications in PHP. It provides:

Install it using Composer:

It requires PHP version 8.2 and supports PHP up to 8.5.

If you like Nette, please make a donation now. Thank you!

Parsing Command-Line Arguments

Every CLI script needs to handle arguments like --verbose, -o output.txt, or plain file names. The Parser class offers the fastest way to get started: just write your help text and let the parser extract option definitions from it:

That's it. The parser understands that --verbose is a switch, --output requires a value, --format has an optional value with json as fallback. Your help text stays in sync with actual option definitions.

The parse() method returns an associative array. Keys match option names exactly as defined, including the dashes:

By default, parse() reads from $_SERVER['argv']. You can pass a custom array for testing:

Help Text Syntax

The parser extracts option definitions from formatted help text:

Syntax Meaning
--verbose Switch (no value)
-v, --verbose Switch with short alias
--output <file> Option with required value
--format [type] Option with optional value
(default: json) Sets fallback value
<path>... Repeatable option

Each line defines one option. Option names must be separated from descriptions by at least two spaces.

Additional Configuration

Some settings can't be expressed in help text. Pass an array as the second parameter, keyed by option name:

Available keys:

Key Description
Parser::Repeatable Collect multiple values into array
Parser::RealPath Validate file exists and resolve to absolute path
Parser::Normalizer Transform function fn($value) => ...
Parser::Default Fallback value (same as (default: x) in help text)
Parser::Enum Array of allowed values

Fluent API

When you need more control over option definitions, use the fluent API with addSwitch(), addOption(), and addArgument() methods. This approach gives you access to all features including normalizers, enums, and precise control over each parameter:

By default, parse() reads from $_SERVER['argv']. You can pass a custom array for testing:

Switches, Options, and Arguments

There are three types of command-line inputs:

Switches are flags without values, like --verbose or -v. They parse as true when present, null when absent:

Options accept values, like --output file.txt. The value can be separated by space or =:

Note that the option itself is always optional - not using it returns null. However, when used, the value is required by default. Set optionalValue: true to allow the option without a value (parses as true):

When the same option is used multiple times without repeatable: true, the last value wins:

Arguments are positional values without dashes. By default they are required. Set optional: true to make them optional:

Use fallback to specify the value when an option or argument is not provided. For options with optionalValue: true, note that using the option without a value still parses as true, while the fallback is used only when the option is not present at all:

Arguments can appear anywhere on the command line - they don't have to come after options:

Restricting Values with Enum

Limit accepted values to a specific set:

Repeatable Options

Set repeatable: true to collect multiple values into an array:

Transforming Values

Use normalizer to transform parsed values:

For file path validation, use the built-in normalizeRealPath:

Mixing Both Approaches

You can combine addFromHelp() with fluent methods when you need normalizers for some options:

Error Handling

The parser throws \Exception for invalid input:

Common error messages:

Error Cause
Option --output requires argument. Option used without required value
Unknown option --foo. Unrecognized option
Missing required argument <file>. Required argument not provided
Unexpected parameter foo. Extra positional argument
Value of option --format must be json, or xml. Value not in enum

Use isEmpty() to check if no command-line arguments were provided (i.e., user ran just script.php with nothing after it):

Handling --help and --version

When your script has required arguments, running script.php --help would normally fail because the required argument is missing. Use parseOnly() to check for info options first:

The parseOnly() method:

Complete Example

Here's a real-world file converter script combining Parser and Console:

The script accepts commands like:


All versions of command-line with dependencies

PHP Build Version
Package Version
Requires php Version 8.2 - 8.5
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 nette/command-line contains the following files

Loading the files please wait ...