summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-03-17 23:03:53 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-03-17 23:03:53 +0100
commit496e3a6f34d97e44e44340c1fbd2d3cbc262c05c (patch)
tree2bc397e6fd78ac2c07cd2ec02b49fc77b0759409 /_test
parent1359eacbdbff842b241a85ea274a00982fec9267 (diff)
downloadrpg-496e3a6f34d97e44e44340c1fbd2d3cbc262c05c.tar.gz
rpg-496e3a6f34d97e44e44340c1fbd2d3cbc262c05c.tar.bz2
completely new base for CLI scripts
This introduces an abstract base class that command line tools need to inherit from. It provides a simple framework for registering accepted command line options and provides commonly needed things like help output and colored text. Existing CLI scripts still need to be converted.
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/cli_options.test.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php
new file mode 100644
index 000000000..1d121d7ce
--- /dev/null
+++ b/_test/tests/inc/cli_options.test.php
@@ -0,0 +1,56 @@
+<?php
+
+class cli_options extends DokuWikiTest {
+
+ function test_simpleshort() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', true);
+
+ $args = array('-x', 'foo', 'bang');
+ $options->parseOptions($args);
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $args);
+ $this->assertFalse($options->getOpt('nothing'));
+ }
+
+ function test_simplelong1() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', true);
+
+ $args = array('--exclude', 'foo', 'bang');
+ $options->parseOptions($args);
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $args);
+ $this->assertFalse($options->getOpt('nothing'));
+ }
+
+ function test_simplelong2() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', true);
+
+ $args = array('--exclude=foo', 'bang');
+ $options->parseOptions($args);
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $args);
+ $this->assertFalse($options->getOpt('nothing'));
+ }
+
+ function test_complex() {
+ $options = new DokuCLI_Options();
+
+ $options->registerOption('plugins', 'run on plugins only', 'p');
+ $options->registerCommand('status', 'display status info');
+ $options->registerOption('long', 'display long lines', 'l', false, 'status');
+
+ $args = array('-p', 'status', '--long', 'foo');
+ $options->parseOptions($args);
+
+ $this->assertEquals('status', $options->getCmd());
+ $this->assertTrue($options->getOpt('plugins'));
+ $this->assertTrue($options->getOpt('long'));
+ $this->assertEquals(array('foo'), $args);
+ }
+} \ No newline at end of file