Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
11d707e
docs: readme
adhocore Jun 28, 2018
3aec08f
chore: dot files- editorconfig/gitignore/travis
adhocore Jun 28, 2018
fb4348c
chore: composer.json
adhocore Jun 28, 2018
57fe909
test: init- config/bootstrap
adhocore Jun 28, 2018
33ea71f
feat: cli colorizer
adhocore Jun 28, 2018
e2a57c8
feat: cli argument option manager
adhocore Jun 28, 2018
00ee163
feat: wip: cli argv parser
adhocore Jun 28, 2018
8383917
test: fixture
adhocore Jun 28, 2018
8928c70
test: options test
adhocore Jun 28, 2018
863ab85
test: argv parser test [wip]
adhocore Jun 28, 2018
21611ff
Apply fixes from StyleCI
adhocore Jun 28, 2018
3b80f93
Merge pull request #2 from adhocore/analysis-8wlv62
adhocore Jun 28, 2018
768cb3f
Apply fixes from StyleCI
adhocore Jun 28, 2018
05d86f6
Merge pull request #3 from adhocore/analysis-XNkm7p
adhocore Jun 28, 2018
51b34b2
build: travis phpunit support for php5.6
adhocore Jun 28, 2018
b9e194e
chore: drop php5 support :/
adhocore Jun 29, 2018
bea3d9c
chore: drop php5 support :/
adhocore Jun 29, 2018
3bd2103
chore: add docblocks and typehints
adhocore Jun 29, 2018
8ca8dce
chore: add typehints
adhocore Jun 29, 2018
f3c3b87
refactor(color): add more colors, remove mute, add typehints, extend …
adhocore Jun 29, 2018
7a36196
fix: option typehint, color eol supprot
adhocore Jun 29, 2018
d8a5909
feat: writer for cli
adhocore Jun 29, 2018
f9c960b
refactor(color): make non static, fix eol shortcut, add ok()
adhocore Jun 29, 2018
89b67e7
refactor(writer): colorizer is no longer static, add typehints
adhocore Jun 29, 2018
70b2a53
test: color
adhocore Jun 29, 2018
b4c2777
test: writer
adhocore Jun 29, 2018
d126041
chore
adhocore Jun 29, 2018
74caaab
chore: composer keyword
adhocore Jun 30, 2018
08617fb
feat: add Argument class
adhocore Jun 30, 2018
245e200
feat: add str inflecton helper
adhocore Jun 30, 2018
dddaa50
feat: add abstract base parser
adhocore Jun 30, 2018
89a42c9
refactor: attributeName, add typehints
adhocore Jun 30, 2018
df075cd
refactor: add arguments(), extract parsing to base class, cleanup
adhocore Jun 30, 2018
8e364e8
test: mock _exit
adhocore Jun 30, 2018
4889993
test: fix fixture exception msg
adhocore Jun 30, 2018
1aa427e
test: cover all
adhocore Jun 30, 2018
43893a5
style: lint
adhocore Jun 30, 2018
836535c
refactor(parser): improve validate()
adhocore Jun 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; http://editorconfig.org
;
; Sublime: https://github.com/sindresorhus/editorconfig-sublime
; Phpstorm: https://plugins.jetbrains.com/plugin/7294-editorconfig

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.md,*.php,composer.json,composer.lock}]
indent_size = 4
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# standards
/.cache/
/.env
/.idea/
/vendor/
composer.lock
*.local.*
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: php

php:
- 7.0
- 7.1
- 7.2

install:
- composer install --prefer-dist

before_script:
- for P in src tests; do find $P -type f -name '*.php' -exec php -l {} \;; done

script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

after_success:
- bash <(curl -s https://codecov.io/bash)
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## adhocore/cli

Command Line Interface utilities and helpers for PHP.

... a work in progress ...

[![Latest Version](https://img.shields.io/github/release/adhocore/cli.svg?style=flat-square)](https://github.com/adhocore/cli/releases)
[![Travis Build](https://img.shields.io/travis/adhocore/cli/master.svg?style=flat-square)](https://travis-ci.org/adhocore/cli?branch=master)
[![Scrutinizer CI](https://img.shields.io/scrutinizer/g/adhocore/cli.svg?style=flat-square)](https://scrutinizer-ci.com/g/adhocore/cli/?branch=master)
[![Codecov branch](https://img.shields.io/codecov/c/github/adhocore/cli/master.svg?style=flat-square)](https://codecov.io/gh/adhocore/cli)
[![StyleCI](https://styleci.io/repos/139012552/shield)](https://styleci.io/repos/139012552)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

- Command line arguments parsing made easy
- Inspired by nodejs [commander](https://github.com/tj/commander.js) (thanks tj)
- For PHP5.6 or new and for good

(*PS: It is just argv parser and not ditto commander, so spawning new commands or actions are not supported*)

**Bonus**: Text coloring for the cli

## Installation
```bash
composer require adhocore/cli
```

## Usage
```php
# coming soon
```
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "adhocore/cli",
"description": "Command line interface library for PHP",
"type": "library",
"keywords": [
"php", "command", "argv-parser", "cli", "cli-color", "cli-action", "console",
"cli-writer", "argument-parser", "cli-option"
],
"license": "MIT",
"authors": [
{
"name": "Jitendra Adhikari",
"email": "jiten.adhikary@gmail.com"
}
],
"autoload": {
"psr-4": {
"Ahc\\Cli\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Ahc\\Cli\\Test\\": "tests/"
}
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
}
}
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
75 changes: 75 additions & 0 deletions src/Argument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Ahc\Cli;

/**
* Cli Option.
*
* @author Jitendra Adhikari <jiten.adhikary@gmail.com>
* @license MIT
*
* @link https://github.com/adhocore/cli
*/
class Argument
{
use InflectsString;

protected $name;

protected $rawArg;

protected $default;

protected $required = false;

protected $variadic = false;

public function __construct(string $arg)
{
$this->rawArg = $arg;

$this->parse($arg);
}

protected function parse(string $arg)
{
$this->required = $arg[0] === '<';
$this->variadic = \strpos($arg, '...') !== false;
$this->name = $name = \str_replace(['<', '>', '[', ']', '.'], '', $arg);

// Format is "name:default+value1,default+value2" ('+'' => ' ')!
if (\strpos($name, ':') !== false) {
$name = \str_replace('+', ' ', $name);
list($this->name, $this->default) = \explode(':', $name, 2);
}
}

public function name(): string
{
return $this->name;
}

public function attributeName(): string
{
return $this->toCamelCase($this->name);
}

public function required(): bool
{
return $this->required;
}

public function variadic(): bool
{
return $this->variadic;
}

public function default()
{
if (!$this->variadic) {
return $this->default;
}

return null === $this->default ? [] : \explode(',', $this->default);
}
}
Loading