1using namespace System.Management.Automation
2using namespace System.Management.Automation.Language
3Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
4 param($wordToComplete, $commandAst, $cursorPosition)
5 $commandElements = $commandAst.CommandElements
6 $command = @(
7 'git-bug'
8 for ($i = 1; $i -lt $commandElements.Count; $i++) {
9 $element = $commandElements[$i]
10 if ($element -isnot [StringConstantExpressionAst] -or
11 $element.StringConstantType -ne [StringConstantType]::BareWord -or
12 $element.Value.StartsWith('-')) {
13 break
14 }
15 $element.Value
16 }
17 ) -join ';'
18 $completions = @(switch ($command) {
19 'git-bug' {
20 [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Create a new bug.')
21 [CompletionResult]::new('bridge', 'bridge', [CompletionResultType]::ParameterValue, 'Configure and use bridges to other bug trackers.')
22 [CompletionResult]::new('commands', 'commands', [CompletionResultType]::ParameterValue, 'Display available commands.')
23 [CompletionResult]::new('comment', 'comment', [CompletionResultType]::ParameterValue, 'Display or add comments to a bug.')
24 [CompletionResult]::new('deselect', 'deselect', [CompletionResultType]::ParameterValue, 'Clear the implicitly selected bug.')
25 [CompletionResult]::new('label', 'label', [CompletionResultType]::ParameterValue, 'Display, add or remove labels to/from a bug.')
26 [CompletionResult]::new('ls', 'ls', [CompletionResultType]::ParameterValue, 'List bugs.')
27 [CompletionResult]::new('ls-id', 'ls-id', [CompletionResultType]::ParameterValue, 'List bug identifiers.')
28 [CompletionResult]::new('ls-label', 'ls-label', [CompletionResultType]::ParameterValue, 'List valid labels.')
29 [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull bugs update from a git remote.')
30 [CompletionResult]::new('push', 'push', [CompletionResultType]::ParameterValue, 'Push bugs update to a git remote.')
31 [CompletionResult]::new('select', 'select', [CompletionResultType]::ParameterValue, 'Select a bug for implicit use in future commands.')
32 [CompletionResult]::new('show', 'show', [CompletionResultType]::ParameterValue, 'Display the details of a bug.')
33 [CompletionResult]::new('status', 'status', [CompletionResultType]::ParameterValue, 'Display or change a bug status.')
34 [CompletionResult]::new('termui', 'termui', [CompletionResultType]::ParameterValue, 'Launch the terminal UI.')
35 [CompletionResult]::new('title', 'title', [CompletionResultType]::ParameterValue, 'Display or change a title of a bug.')
36 [CompletionResult]::new('user', 'user', [CompletionResultType]::ParameterValue, 'Display or change the user identity.')
37 [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, 'Show git-bug version information.')
38 [CompletionResult]::new('webui', 'webui', [CompletionResultType]::ParameterValue, 'Launch the web UI.')
39 break
40 }
41 'git-bug;add' {
42 [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Provide a title to describe the issue')
43 [CompletionResult]::new('--title', 'title', [CompletionResultType]::ParameterName, 'Provide a title to describe the issue')
44 [CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Provide a message to describe the issue')
45 [CompletionResult]::new('--message', 'message', [CompletionResultType]::ParameterName, 'Provide a message to describe the issue')
46 [CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'Take the message from the given file. Use - to read the message from the standard input')
47 [CompletionResult]::new('--file', 'file', [CompletionResultType]::ParameterName, 'Take the message from the given file. Use - to read the message from the standard input')
48 break
49 }
50 'git-bug;bridge' {
51 [CompletionResult]::new('configure', 'configure', [CompletionResultType]::ParameterValue, 'Configure a new bridge.')
52 [CompletionResult]::new('pull', 'pull', [CompletionResultType]::ParameterValue, 'Pull updates.')
53 [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Delete a configured bridge.')
54 break
55 }
56 'git-bug;bridge;configure' {
57 [CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'A distinctive name to identify the bridge')
58 [CompletionResult]::new('--name', 'name', [CompletionResultType]::ParameterName, 'A distinctive name to identify the bridge')
59 [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,launchpad-preview]')
60 [CompletionResult]::new('--target', 'target', [CompletionResultType]::ParameterName, 'The target of the bridge. Valid values are [github,launchpad-preview]')
61 [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'The URL of the target repository')
62 [CompletionResult]::new('--url', 'url', [CompletionResultType]::ParameterName, 'The URL of the target repository')
63 [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'The owner of the target repository')
64 [CompletionResult]::new('--owner', 'owner', [CompletionResultType]::ParameterName, 'The owner of the target repository')
65 [CompletionResult]::new('-T', 'T', [CompletionResultType]::ParameterName, 'The authentication token for the API')
66 [CompletionResult]::new('--token', 'token', [CompletionResultType]::ParameterName, 'The authentication token for the API')
67 [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'The name of the target repository')
68 [CompletionResult]::new('--project', 'project', [CompletionResultType]::ParameterName, 'The name of the target repository')
69 break
70 }
71 'git-bug;bridge;pull' {
72 break
73 }
74 'git-bug;bridge;rm' {
75 break
76 }
77 'git-bug;commands' {
78 [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment')
79 [CompletionResult]::new('--pretty', 'pretty', [CompletionResultType]::ParameterName, 'Output the command description as well as Markdown compatible comment')
80 break
81 }
82 'git-bug;comment' {
83 [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Add a new comment to a bug.')
84 break
85 }
86 'git-bug;comment;add' {
87 [CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'Take the message from the given file. Use - to read the message from the standard input')
88 [CompletionResult]::new('--file', 'file', [CompletionResultType]::ParameterName, 'Take the message from the given file. Use - to read the message from the standard input')
89 [CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Provide the new message from the command line')
90 [CompletionResult]::new('--message', 'message', [CompletionResultType]::ParameterName, 'Provide the new message from the command line')
91 break
92 }
93 'git-bug;deselect' {
94 break
95 }
96 'git-bug;label' {
97 [CompletionResult]::new('add', 'add', [CompletionResultType]::ParameterValue, 'Add a label to a bug.')
98 [CompletionResult]::new('rm', 'rm', [CompletionResultType]::ParameterValue, 'Remove a label from a bug.')
99 break
100 }
101 'git-bug;label;add' {
102 break
103 }
104 'git-bug;label;rm' {
105 break
106 }
107 'git-bug;ls' {
108 [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Filter by status. Valid values are [open,closed]')
109 [CompletionResult]::new('--status', 'status', [CompletionResultType]::ParameterName, 'Filter by status. Valid values are [open,closed]')
110 [CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'Filter by author')
111 [CompletionResult]::new('--author', 'author', [CompletionResultType]::ParameterName, 'Filter by author')
112 [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Filter by participant')
113 [CompletionResult]::new('--participant', 'participant', [CompletionResultType]::ParameterName, 'Filter by participant')
114 [CompletionResult]::new('-A', 'A', [CompletionResultType]::ParameterName, 'Filter by actor')
115 [CompletionResult]::new('--actor', 'actor', [CompletionResultType]::ParameterName, 'Filter by actor')
116 [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Filter by label')
117 [CompletionResult]::new('--label', 'label', [CompletionResultType]::ParameterName, 'Filter by label')
118 [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Filter by title')
119 [CompletionResult]::new('--title', 'title', [CompletionResultType]::ParameterName, 'Filter by title')
120 [CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Filter by absence of something. Valid values are [label]')
121 [CompletionResult]::new('--no', 'no', [CompletionResultType]::ParameterName, 'Filter by absence of something. Valid values are [label]')
122 [CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'Sort the results by a characteristic. Valid values are [id,creation,edit]')
123 [CompletionResult]::new('--by', 'by', [CompletionResultType]::ParameterName, 'Sort the results by a characteristic. Valid values are [id,creation,edit]')
124 [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Select the sorting direction. Valid values are [asc,desc]')
125 [CompletionResult]::new('--direction', 'direction', [CompletionResultType]::ParameterName, 'Select the sorting direction. Valid values are [asc,desc]')
126 break
127 }
128 'git-bug;ls-id' {
129 break
130 }
131 'git-bug;ls-label' {
132 break
133 }
134 'git-bug;pull' {
135 break
136 }
137 'git-bug;push' {
138 break
139 }
140 'git-bug;select' {
141 break
142 }
143 'git-bug;show' {
144 [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]')
145 [CompletionResult]::new('--field', 'field', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]')
146 break
147 }
148 'git-bug;status' {
149 [CompletionResult]::new('close', 'close', [CompletionResultType]::ParameterValue, 'Mark a bug as closed.')
150 [CompletionResult]::new('open', 'open', [CompletionResultType]::ParameterValue, 'Mark a bug as open.')
151 break
152 }
153 'git-bug;status;close' {
154 break
155 }
156 'git-bug;status;open' {
157 break
158 }
159 'git-bug;termui' {
160 break
161 }
162 'git-bug;title' {
163 [CompletionResult]::new('edit', 'edit', [CompletionResultType]::ParameterValue, 'Edit a title of a bug.')
164 break
165 }
166 'git-bug;title;edit' {
167 [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Provide a title to describe the issue')
168 [CompletionResult]::new('--title', 'title', [CompletionResultType]::ParameterName, 'Provide a title to describe the issue')
169 break
170 }
171 'git-bug;user' {
172 [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name]')
173 [CompletionResult]::new('--field', 'field', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name]')
174 [CompletionResult]::new('adopt', 'adopt', [CompletionResultType]::ParameterValue, 'Adopt an existing identity as your own.')
175 [CompletionResult]::new('create', 'create', [CompletionResultType]::ParameterValue, 'Create a new identity.')
176 [CompletionResult]::new('ls', 'ls', [CompletionResultType]::ParameterValue, 'List identities.')
177 break
178 }
179 'git-bug;user;adopt' {
180 break
181 }
182 'git-bug;user;create' {
183 break
184 }
185 'git-bug;user;ls' {
186 break
187 }
188 'git-bug;version' {
189 [CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Only show the version number')
190 [CompletionResult]::new('--number', 'number', [CompletionResultType]::ParameterName, 'Only show the version number')
191 [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Only show the commit hash')
192 [CompletionResult]::new('--commit', 'commit', [CompletionResultType]::ParameterName, 'Only show the commit hash')
193 [CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'Show all version informations')
194 [CompletionResult]::new('--all', 'all', [CompletionResultType]::ParameterName, 'Show all version informations')
195 break
196 }
197 'git-bug;webui' {
198 [CompletionResult]::new('--open', 'open', [CompletionResultType]::ParameterName, 'Automatically open the web UI in the default browser')
199 [CompletionResult]::new('--no-open', 'no-open', [CompletionResultType]::ParameterName, 'Prevent the automatic opening of the web UI in the default browser')
200 [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Port to listen to (default is random)')
201 [CompletionResult]::new('--port', 'port', [CompletionResultType]::ParameterName, 'Port to listen to (default is random)')
202 break
203 }
204 })
205 $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
206 Sort-Object -Property ListItemText
207}