You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-13Lines changed: 22 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,32 @@
1
1
# Symfony Console completion
2
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.
3
+
This package provides automatic BASH completion for Symfony Console Component based applications. With minimal configuration, this package allows completion of available command names and the options they provide. Custom completion behaviour can be added for option and argument values by name.
4
4
5
-
## Use
5
+
## Basic use
6
6
7
-
If you don't need any custom completion behaviour, just add an instance of `CompletionCommand` to your application's `Application::getDefaultCommands()` method. Once you've done this, you can run this line of BASH to enable completion:
7
+
If you don't need any custom completion behaviour:
1. Install `stecman/symfony-console-completion` through composer
10
+
2. Add an instance of `CompletionCommand` to your application's `Application::getDefaultCommands()`:
11
+
```
12
+
protected function getDefaultCommands()
13
+
{
14
+
...
15
+
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
16
+
...
17
+
}
18
+
```
10
19
11
-
Where `[program-name]` is the name you want to register bash completion for. This will be the same as `[your-application]` if your application is in your PATH.
20
+
3. Run `eval $([your-application] _completion -g [program-name])` in a terminal, where `[program-name]` is the name you want to register bash completion for (this will be the same as `[your-application]` if your application is on your PATH).
21
+
4. Add the above command to your bash profile if you want the completion to apply automatically for new terminal sessions.
12
22
13
-
This will generate and run a small bash script which creates a small wrapper function and registers completion for your appliction name. Completion is then handled by running your application as`[your-application] _completion`.
23
+
The command `_completion -g [program-name]` (`-g` being a shortcut for `--genhook`) generates a few lines of bash that, when run, register your application as a completion handler for `[program-name]`. Completion is handled by running the completion command on your application with no arguments:`[your-application] _completion`.
14
24
15
-
###Custom completion
25
+
## Custom completion
16
26
17
-
Custom completion behaviour for arguments and option values can be added by sub-classing `CompletionCommand`:
27
+
Custom completion behaviour for argument and option values can be added by sub-classing `CompletionCommand`.
18
28
29
+
The following examples are for an application with this signature: `myapp (walk|run) [-w|--weather=""] direction`
19
30
20
31
class MyCompletionCommand extends CompletionCommand{
21
32
@@ -33,8 +44,6 @@ Custom completion behaviour for arguments and option values can be added by sub-
33
44
34
45
}
35
46
36
-
Imagine you have an application with this signature: `myapp (walk|run) [-w|--weather=""] direction`
37
-
38
47
39
48
**Command-specific argument completion with an array:**
40
49
@@ -52,7 +61,7 @@ but not this:
52
61
myapp run [tab]
53
62
54
63
55
-
**Non-command-specifc (global) argument completion with a function**
64
+
**Non-command-specific (global) argument completion with a function**
56
65
57
66
Completion::makeGlobalHandler(
58
67
'direction', Completion::TYPE_ARGUMENT,
@@ -75,7 +84,7 @@ This will complete for both commands:
75
84
76
85
Option handlers work the same way as argument handlers, except you use `Completion::TYPE_OPTION` for the type.
77
86
78
-
**Note this functionality is not yet complete:** long-form options (eg `--hello="world"`) do not support completion yet. Only option shortcut completion works (eg. `-h [tab]`).
87
+
**Note this functionality is not yet complete:** long-form options (eg `--hello="world"`) do not support completion yet. Option completion is only supported for shortcuts (eg. `-h [tab]`).
79
88
80
89
Completion::makeGlobalHandler(
81
90
'weather', Completion::TYPE_OPTION,
@@ -88,4 +97,4 @@ Option completion is only supported for shortcuts currently:
88
97
89
98
## Notes
90
99
91
-
Option shorcuts are not offered as completion options, however requesting completion (ie. pressing tab) on a valid option shortcut will complete.
100
+
*Option shorcuts are not offered as completion options, however requesting completion (ie. pressing tab) on a valid option shortcut will complete.
0 commit comments