Skip to content

Commit 5956089

Browse files
committed
Add readme.md
1 parent 0ce2f58 commit 5956089

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Symfony Console completion
2+
3+
Automatic BASH completion for Symfony Console Component based applications. Completes commands and options by default, and allows for custom option/argument completion handlers to be set.
4+
5+
**Note that this is not entirely finished:**
6+
7+
* Long-form options do not support completion yet (only shortcuts do)
8+
9+
## Use
10+
11+
If you don't need any custom completion behaviour, just add an instance of `CompletionCommand` to your application's `Application::getDefaultCommands()` method.
12+
13+
14+
### Custom completion
15+
16+
Custom completion behaviour for arguments and option values can be added by sub-classing `CompletionCommand` (this will change very soon):
17+
18+
19+
class BeamCompletionCommand extends CompletionCommand{
20+
21+
protected function runCompletion()
22+
{
23+
$handler = $this->handler;
24+
$handler->addHandlers(array(
25+
26+
... // See below for what goes in here
27+
28+
));
29+
30+
return $handler->runCompletion();
31+
}
32+
33+
}
34+
35+
Imagine you have an application with this signature: `myapp (walk|run) [-w|--weather=""] direction`
36+
37+
38+
**Command-specific argument completion with an array:**
39+
40+
new Completion(
41+
'walk', 'direction', Completion::TYPE_ARGUMENT,
42+
array('north', 'east', 'south', 'west')
43+
)
44+
45+
This will complete for this:
46+
47+
myapp walk [tab]
48+
49+
but not this:
50+
51+
myapp run [tab]
52+
53+
54+
**Non-command-specifc (global) argument completion with a function**
55+
56+
Completion::makeGlobalHandler(
57+
'direction', Completion::TYPE_ARGUMENT,
58+
function(){
59+
$values = array();
60+
61+
// Fill the array up with stuff
62+
63+
return $values;
64+
}
65+
)
66+
67+
This will complete for both commands:
68+
69+
myapp walk [tab]
70+
myapp run [tab]
71+
72+
73+
**Option completion**
74+
75+
Option handlers work the same way as argument handlers, except you use `Completion::TYPE_OPTION` for the type.
76+
77+
Completion::makeGlobalHandler(
78+
'weather', Completion::TYPE_OPTION,
79+
array('raining', 'sunny', 'everything is on fire!')
80+
)
81+
82+
Option completion is only supported for shortcuts currently:
83+
84+
myapp walk -w [tab]
85+
86+
## Notes
87+
88+
Option shorcuts are not offered as completion options, however requesting completion (ie. pressing tab) on a valid option shortcut will complete.

0 commit comments

Comments
 (0)