Skip to content

Commit 74015b8

Browse files
committed
Merge pull request #2 from mhor/patch-1
Syntax highlighting on README.md
2 parents 820837f + f547214 commit 74015b8

File tree

1 file changed

+80
-63
lines changed

1 file changed

+80
-63
lines changed

README.md

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ If you don't need any custom completion behaviour, all you need to do is add the
1212

1313
1. Install `stecman/symfony-console-completion` through composer
1414
2. Add an instance of `CompletionCommand` to your application's `Application::getDefaultCommands()` method:
15-
```
16-
protected function getDefaultCommands()
17-
{
18-
...
19-
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
20-
...
21-
}
15+
```php
16+
protected function getDefaultCommands()
17+
{
18+
//...
19+
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
20+
//...
21+
}
2222
```
2323

2424
3. Run `eval $([program] _completion --generate-hook)` in a terminal, replacing `[program]` with the command you use to run your application (eg. 'composer'). By default this registers completion for the absolute path to you application; you can specify a command name to complete for instead using the `-p` option.
@@ -37,89 +37,106 @@ Custom completion behaviour for argument and option values can be added by sub-c
3737

3838
The following examples are for an application with this signature: `myapp (walk|run) [-w|--weather=""] direction`
3939

40-
class MyCompletionCommand extends CompletionCommand{
41-
42-
protected function runCompletion()
43-
{
44-
$this->handler->addHandlers(array(
45-
46-
// Instances of Completion go here.
47-
// See below for examples.
48-
49-
));
50-
51-
return $this->handler->runCompletion();
52-
}
40+
```php
41+
class MyCompletionCommand extends CompletionCommand {
5342

43+
protected function runCompletion()
44+
{
45+
$this->handler->addHandlers(array(
46+
// Instances of Completion go here.
47+
// See below for examples.
48+
));
49+
return $this->handler->runCompletion();
5450
}
55-
51+
}
52+
```
5653

5754
**Command-specific argument completion with an array:**
58-
59-
$this->handler->addHandler(
60-
new Completion(
61-
'walk', 'direction', Completion::TYPE_ARGUMENT,
62-
array('north', 'east', 'south', 'west')
55+
56+
```php
57+
$this->handler->addHandler(
58+
new Completion(
59+
'walk',
60+
'direction',
61+
Completion::TYPE_ARGUMENT,
62+
array(
63+
'north',
64+
'east',
65+
'south',
66+
'west'
6367
)
64-
);
68+
)
69+
);
70+
```
6571

6672
This will complete for this:
67-
68-
myapp walk [tab]
73+
```bash
74+
$ myapp walk [tab]
75+
```
6976

7077
but not this:
71-
72-
myapp run [tab]
73-
78+
```bash
79+
$ myapp run [tab]
80+
```
7481

7582
**Non-command-specific (global) argument completion with a function**
7683

77-
$this->handler->addHandler(
78-
Completion::makeGlobalHandler(
79-
'direction', Completion::TYPE_ARGUMENT,
80-
function(){
81-
$values = array();
82-
83-
// Fill the array up with stuff
84+
```php
85+
$this->handler->addHandler(
86+
Completion::makeGlobalHandler(
87+
'direction',
88+
Completion::TYPE_ARGUMENT,
89+
function() {
90+
$values = array();
8491

85-
return $values;
86-
}
87-
)
88-
);
92+
// Fill the array up with stuff
93+
return $values;
94+
}
95+
)
96+
);
97+
```
8998

9099
This will complete for both commands:
91-
92-
myapp walk [tab]
93-
myapp run [tab]
94-
100+
```bash
101+
$ myapp walk [tab]
102+
$ myapp run [tab]
103+
```
95104

96105
**Option completion**
97106

98107
Option handlers work the same way as argument handlers, except you use `Completion::TYPE_OPTION` for the type..
99108

100-
$this->handler->addHandler(
101-
Completion::makeGlobalHandler(
102-
'weather', Completion::TYPE_OPTION,
103-
array('raining', 'sunny', 'everything is on fire!')
109+
```php
110+
$this->handler->addHandler(
111+
Completion::makeGlobalHandler(
112+
'weather',
113+
Completion::TYPE_OPTION,
114+
array(
115+
'raining',
116+
'sunny',
117+
'everything is on fire!'
104118
)
105-
);
106-
119+
)
120+
);
121+
```
107122

108123
### Example: completing references from a Git repository
109124

110-
Completion::makeGlobalHandler(
111-
'ref',
112-
Completion::TYPE_OPTION,
113-
function () {
114-
$raw = shell_exec('git show-ref --abbr');
115-
if (preg_match_all('/refs\/(?:heads|tags)?\/?(.*)/', $raw, $matches)) {
116-
return $matches[1];
117-
}
125+
```php
126+
Completion::makeGlobalHandler(
127+
'ref',
128+
Completion::TYPE_OPTION,
129+
function () {
130+
$raw = shell_exec('git show-ref --abbr');
131+
if (preg_match_all('/refs\/(?:heads|tags)?\/?(.*)/', $raw, $matches)) {
132+
return $matches[1];
118133
}
119-
)
134+
}
135+
)
136+
```
120137

121138
## Behaviour notes
122139

123140
* Option shortcuts are not offered as completion options, however requesting completion (ie. pressing tab) on a valid option shortcut will complete.
124141
* Completion is not implemented for the `--option="value"` style of passing a value to an option, however `--option value` and `--option "value"` work and are functionally identical.
125-
* There is currently no way to hand-off to BASH to complete folder/file names.
142+
* There is currently no way to hand-off to BASH to complete folder/file names.

0 commit comments

Comments
 (0)