Skip to content

Instantly share code, notes, and snippets.

@klaude
Last active August 29, 2015 14:13
Show Gist options
  • Save klaude/ad4497edb7150ce83da4 to your computer and use it in GitHub Desktop.
Save klaude/ad4497edb7150ce83da4 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use League\CLImate\CLImate;
$climate = new CLImate;
$climate->description('test');
$climate->arguments->add(
'help',
[
'prefix' => 'h',
'longPrefix' => 'help',
'description' => 'Print a usage statement',
'definedOnly' => true
]
);
$climate->arguments->add(
'force',
[
'prefix' => 'f',
'longPrefix' => 'force',
'description' => 'Force the issue',
'definedOnly' => true
]
);
$climate->arguments->add(
'user',
[
'prefix' => 'u',
'longPrefix' => 'user',
'description' => 'Connect username',
'required' => true,
]
);
$climate->arguments->add(
'host',
[
'prefix' => 'H',
'longPrefix' => 'host',
'description' => 'Connect hostname',
'required' => true,
]
);
if ($climate->arguments->defined('help')) {
$climate->usage();
exit();
}
$climate->arguments->parse();
$climate->out("Username: {$climate->arguments->get('user')}");
$climate->out("Hostname: {$climate->arguments->get('host')}");
// Output:
//✯ climate [argument_support] ⚡ php ./scratch.php -h
//test
//
//Usage: ./scratch.php
//
//Required Arguments:
// -u user, --user user
// Connect username
// -H host, --host host
// Connect hostname
//
//Optional Arguments:
// -h, --help
// Print a usage statement
// -f, --force
// Force the issue
//✯ climate [argument_support] ⚡ php ./scratch.php -u kevin -H lol.net
//Username: kevin
//Hostname: lol.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment