An open API service indexing awesome lists of open source software.

https://github.com/jabernardo/console.php

Command-line Application Skeleton for PHP
https://github.com/jabernardo/console.php

command-line command-line-arguments-parser php-cli

Last synced: 10 days ago
JSON representation

Command-line Application Skeleton for PHP

Awesome Lists containing this project

README

          

# console.php
`console.php` is a skeleton for php command-line application.

```php

#!/usr/bin/php
hasOptions(['name', 'age'])) {
$o->writeln('Invalid args.');
return;
}

$o->writeln('Hello %s! So you are %d years old.', $i->getOption('name'), $i->getOption('age'));
}
}

// Instantiate a new console application
$app = new \Console\Application();

// Register our test HelloCommand to our console application
$app->add('hello', new HelloCommand());

// You can also just declare a command by using callables
$app->add('help', function($i, $o) {
$o->writeln('This is a sample application.');
}, true); // <-- `true` is to enable this as the default command

// Finally, App and Running!
$app->run();

```

## Input

### hasFlag `:boolean`
Check if flag was passed on application.

```php
hasFlag('q')) {
// Do something
}
}
}

```

### hasOption `:boolean`
Check if option was passed on application.

```php
hasOption('max')) {
// Do something
}
}
}

```

### hasOptions `:boolean`
Check if option(s) was passed on application.

```php
hasOptions(['age', 'name'])) {
// Do something
}
}
}

```

### getOption `:mixed`
Returns the value of option being passed on.

```php
hasOption('max')) {
$this->max = $i->getOption('max');
}
}
}

```

### getOptions `:array`
Returns all options.

```php
getOptions();
}
}

```

### setOptionDelimeter `:void`
Set option delimeter (default value is `:`)

```php
setOptionDelimeter('=');
$options = $i->getOptions();
}
}

```

### getOptionDelimeter `:string`
Get option delimeter (default value is `:`)

### getParameters `:array`
Returns all parameters.

```php
getParameters();
}
}

```

## Output

### write `:void`
Write string buffer.

```php
write('Hello %s!', $i->getOption('name'));
}
}

```

### writeln `:void`
Write a line of string.

```php
write('Hello %s! So you\'re %d years old.', $i->getOption('name'), $i->getOption('age'));
}
}

```

## License

The `console.php` is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).