Skip to content
/ clp Public

php command line parser for $argv in composer siims/clp

License

Notifications You must be signed in to change notification settings

siims-biz/clp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clp

php command line parser for $argv in composer siims/clp

Usage 2023-04-21

Option1
# Scroll down for Example1.php
composer create-project siims/clp .
php Example1.php --help hello=world debug
php Example2.php --help hello="hello world" --try-run

Option2
composer require siims/clp

With create-project you get a copy of the original composer.json.
With require you get a new composer.json or the existing composer.json gets updated.

Known Issues

The tool has not been designed to work with single apostophs.

php Example1.php --help hello='her is my world'
--> may not work as expected
php Example1.php --help hello="'her is my world'"
--> may work as expected

The package also does not support something like
php Example1.php -file Example2.php
--> will not work as expected

Alternative PHP Packages

Example1.php

<?php
/* License: OSL-3.0
   To be launched in shell environment
   php Example1.php
*/

require 'vendor/autoload.php';
use Siims\clp\clp;

$options = [
    "actions" => [
        "h|help" => "displayHelp",
        "hello" => "callHello"
    ],
    "flags" => [
        "try-run","verbose","debug"
    ],
    "values" => [
        "hello" => "world"
    ],
    "events" => [
        "onAfterProcess" => "parsingCommandLineFinished",
        "onNoOptions" => "displayHelp"
    ]
    ];

$hello = new clp($argv,$options);

function displayHelp() {
    global $argv;
    echo "$argv[0] hello=\"your_name\" | --h | -help | verbose | debug\n";
}

function parsingCommandLineFinished($config) {
    echo "Finished parsing command line.\n";
    print_r($config);
}

function callHello($config,$method) {
    echo "Hello {$config["values"]["hello"]}\n";
    echo "Implemented by $method\n";
}

About

php command line parser for $argv in composer siims/clp

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages