1import argparse
2
3import bugz.cli
4
5from bugz.definitions import __version__
6
7
8def make_arg_parser():
9    parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
10    parser.add_argument('--config-file',
11                        help='read an alternate configuration file')
12    parser.add_argument('--connection',
13                        help='use [connection] section of your '
14                        'configuration file')
15    parser.add_argument('-b', '--base',
16                        help='base URL of Bugzilla')
17    parser.add_argument('-u', '--user',
18                        help='username')
19    parser.add_argument('-p', '--password',
20                        help='password')
21    parser.add_argument('--passwordcmd',
22                        help='command to evaluate for the password')
23    parser.add_argument('-k', '--key',
24                        help='API key')
25    parser.add_argument('-q', '--quiet',
26                        action='store_true',
27                        help='quiet mode')
28    parser.add_argument('-d', '--debug',
29                        type=int,
30                        help='debug level (from 0 to 3)')
31    parser.add_argument('--columns',
32                        type=int,
33                        help='maximum number of columns output should use')
34    parser.add_argument('--encoding',
35                        help='output encoding (default: utf-8) (deprecated)')
36    parser.add_argument('--skip-auth',
37                        action='store_true',
38                        help='skip Authentication.')
39    parser.add_argument('--insecure',
40                        action='store_true',
41                        help='do not verify ssl certificate')
42    parser.add_argument('--version',
43                        action='version',
44                        help='show program version and exit',
45                        version='%(prog)s ' + __version__)
46
47    subparsers = parser.add_subparsers(title='sub-commands',
48                                       description='use -h after '
49                                       'a sub-command for more help')
50
51    attach_parser = subparsers.add_parser('attach',
52                                          argument_default=argparse.SUPPRESS,
53                                          help='attach file to a bug')
54    attach_parser.add_argument('bugid',
55                               help='the ID of the bug where the file '
56                               'should be attached')
57    attach_parser.add_argument('filename',
58                               help='the name of the file to attach')
59    attach_parser.add_argument('-c', '--content-type',
60                               help='mimetype of the file e.g. '
61                               'text/plain (default: auto-detect)')
62    attach_parser.add_argument('-d', '--description',
63                               dest='comment',
64                               help='a long description of the attachment')
65    attach_parser.add_argument('-p', '--patch',
66                               action='store_true',
67                               dest='is_patch',
68                               help='attachment is a patch')
69    attach_parser.add_argument('-t', '--title',
70                               dest='summary',
71                               help='a short description of the '
72                               'attachment (default: filename).')
73    attach_parser.set_defaults(func=bugz.cli.attach)
74
75    attachment_parser = subparsers.add_parser('attachment',
76                                              argument_default=argparse.SUPPRESS,
77                                              help='get an attachment '
78                                              'from Bugzilla')
79    attachment_parser.add_argument('attachid',
80                                   help='the ID of the attachment')
81    attachment_parser.add_argument('-v', '--view',
82                                   action="store_true",
83                                   help='print attachment rather than save')
84    attachment_parser.set_defaults(func=bugz.cli.attachment)
85
86    connections_parser = subparsers.add_parser('connections',
87                                               help='list known bug trackers')
88    connections_parser.set_defaults(func=bugz.cli.connections)
89
90    get_parser = subparsers.add_parser('get',
91                                       argument_default=argparse.SUPPRESS,
92                                       help='get a bug from bugzilla')
93    get_parser.add_argument('bugid',
94                            help='the ID of the bug to retrieve')
95    get_parser.add_argument("-a", "--no-attachments",
96                            action="store_true",
97                            help='do not show attachments')
98    get_parser.add_argument("-n", "--no-comments",
99                            action="store_true",
100                            help='do not show comments')
101    get_parser.set_defaults(func=bugz.cli.get)
102
103    modify_parser = subparsers.add_parser('modify',
104                                          argument_default=argparse.SUPPRESS,
105                                          help='modify a bug '
106                                          '(eg. post a comment)')
107    modify_parser.add_argument('bugid',
108                               help='the ID of the bug to modify')
109    modify_parser.add_argument('--alias',
110                               help='change the alias for this bug')
111    modify_parser.add_argument('-a', '--assigned-to',
112                               help='change assignee for this bug')
113    modify_parser.add_argument('--add-blocked',
114                               action='append',
115                               dest='blocks_add',
116                               help='add a bug to the blocked list')
117    modify_parser.add_argument('--remove-blocked',
118                               action='append',
119                               dest='blocks_remove',
120                               help='remove a bug from the blocked list')
121    modify_parser.add_argument('--add-dependson',
122                               action='append',
123                               dest='depends_on_add',
124                               help='add a bug to the depends list')
125    modify_parser.add_argument('--remove-dependson',
126                               action='append',
127                               dest='depends_on_remove',
128                               help='remove a bug from the depends list')
129    modify_parser.add_argument('--add-cc',
130                               action='append',
131                               dest='cc_add',
132                               help='add an email to the CC list')
133    modify_parser.add_argument('--remove-cc',
134                               action='append',
135                               dest='cc_remove',
136                               help='remove an email from the CC list')
137    modify_parser.add_argument('-c', '--comment',
138                               help='add comment from command line')
139    modify_parser.add_argument('-C', '--comment-editor',
140                               action='store_true',
141                               help='add comment via default editor')
142    modify_parser.add_argument('-F', '--comment-from',
143                               help='add comment from file.  If -C is '
144                               'also specified, the editor will be opened '
145                               'with this file as its contents.')
146    modify_parser.add_argument('--component',
147                               help='change the component for this bug')
148    modify_parser.add_argument('--deadline',
149                               help='deadline for bug (format YYYY-MM-DD)')
150    modify_parser.add_argument('-d', '--duplicate',
151                               dest='dupe_of',
152                               type=int,
153                               help='this bug is a duplicate')
154    modify_parser.add_argument('--estimated-time',
155                               dest='estimated_time',
156                               type=float,
157                               help='The total estimate of time required to '
158                               'fix the bug, in hours')
159    modify_parser.add_argument('--remaining-time',
160                               dest='remaining_time',
161                               type=float,
162                               help='How much work time is remaining to fix '
163                               'the bug, in hours')
164    modify_parser.add_argument('--work-time',
165                               dest='work_time',
166                               type=float,
167                               help='The number of hours spent on this bug')
168    modify_parser.add_argument('--add-group',
169                               action='append',
170                               dest='groups_add',
171                               help='add a group to this bug')
172    modify_parser.add_argument('--remove-group',
173                               action='append',
174                               dest='groups_remove',
175                               help='remove agroup from this bug')
176    modify_parser.add_argument('--set-keywords',
177                               action='append',
178                               dest='keywords_set',
179                               help='set bug keywords')
180    modify_parser.add_argument('--op-sys',
181                               help='change the operating system for this bug')
182    modify_parser.add_argument('--platform',
183                               help='change the hardware platform '
184                               'for this bug')
185    modify_parser.add_argument('--priority',
186                               help='change the priority for this bug')
187    modify_parser.add_argument('--product',
188                               help='change the product for this bug')
189    modify_parser.add_argument('-r', '--resolution',
190                               help='set new resolution '
191                               '(if status = RESOLVED)')
192    modify_parser.add_argument('--add-see-also',
193                               action='append',
194                               dest='see_also_add',
195                               help='add a "see also" URL to this bug')
196    modify_parser.add_argument('--remove-see-also',
197                               action='append',
198                               dest='see_also_remove',
199                               help='remove a"see also" URL from this bug')
200    modify_parser.add_argument('-S', '--severity',
201                               help='set severity for this bug')
202    modify_parser.add_argument('-s', '--status',
203                               help='set new status of bug (eg. RESOLVED)')
204    modify_parser.add_argument('-t', '--title',
205                               dest='summary',
206                               help='set title of bug')
207    modify_parser.add_argument('-u', '--unassign',
208                               action='store_true',
209                               dest='reset_assigned_to',
210                               help='Reassign the bug to the default owner')
211    modify_parser.add_argument('-U', '--url',
212                               help='set URL field of bug')
213    modify_parser.add_argument('-v', '--version',
214                               help='set the version for this bug'),
215    modify_parser.add_argument('-w', '--whiteboard',
216                               help='set Status whiteboard'),
217    modify_parser.add_argument('--fixed',
218                               action='store_true',
219                               help='mark bug as RESOLVED, FIXED')
220    modify_parser.add_argument('--invalid',
221                               action='store_true',
222                               help='mark bug as RESOLVED, INVALID')
223    modify_parser.set_defaults(func=bugz.cli.modify)
224
225    post_parser = subparsers.add_parser('post',
226                                        argument_default=argparse.SUPPRESS,
227                                        help='post a new bug into bugzilla')
228    post_parser.add_argument('--product',
229                             help='product')
230    post_parser.add_argument('--component',
231                             help='component')
232    post_parser.add_argument('--version',
233                             help='version of the product')
234    post_parser.add_argument('-t', '--title',
235                             dest='summary',
236                             help='title of bug')
237    post_parser.add_argument('-d', '--description',
238                             help='description of the bug')
239    post_parser.add_argument('--op-sys',
240                             help='set the operating system')
241    post_parser.add_argument('--platform',
242                             help='set the hardware platform')
243    post_parser.add_argument('--priority',
244                             help='set priority for the new bug')
245    post_parser.add_argument('-S', '--severity',
246                             help='set the severity for the new bug')
247    post_parser.add_argument('--alias',
248                             help='set the alias for this bug')
249    post_parser.add_argument('-a', '--assigned-to',
250                             help='assign the bug to someone')
251    post_parser.add_argument('--cc',
252                             help='add a list of emails to CC list')
253    post_parser.add_argument('-U', '--url',
254                             help='set URL field of bug')
255    post_parser.add_argument('-F', '--description-from',
256                             help='load description from file')
257    post_parser.add_argument('--append-command',
258                             help='append output from command to description')
259    post_parser.add_argument('--batch',
260                             action="store_true",
261                             help='do not prompt for any values')
262    post_parser.add_argument('--default-confirm',
263                             choices=['y', 'Y', 'n', 'N'],
264                             default='y',
265                             help='default answer to confirmation question')
266    post_parser.set_defaults(func=bugz.cli.post)
267
268    search_parser = subparsers.add_parser('search',
269                                          argument_default=argparse.SUPPRESS,
270                                          help='search for bugs in bugzilla')
271    search_parser.add_argument('terms',
272                               nargs='*',
273                               help='strings to search for in '
274                               'the title and/or body')
275    search_parser.add_argument('--alias',
276                               help='The unique alias for this bug')
277    search_parser.add_argument('-a', '--assigned-to',
278                               help='email the bug is assigned to')
279    search_parser.add_argument('-C', '--component',
280                               action='append',
281                               help='restrict by component (1 or more)')
282    search_parser.add_argument('-r', '--creator',
283                               help='email of the person who created the bug')
284    search_parser.add_argument('-l', '--limit',
285                               type=int,
286                               help='Limit the number of records '
287                               'returned by a search')
288    search_parser.add_argument('--offset',
289                               type=int,
290                               help='Set the start position for a search')
291    search_parser.add_argument('--op-sys',
292                               action='append',
293                               help='restrict by Operating System '
294                               '(one or more)')
295    search_parser.add_argument('--platform',
296                               action='append',
297                               help='restrict by platform (one or more)')
298    search_parser.add_argument('--priority',
299                               action='append',
300                               help='restrict by priority (one or more)')
301    search_parser.add_argument('--product',
302                               action='append',
303                               help='restrict by product (one or more)')
304    search_parser.add_argument('--resolution',
305                               help='restrict by resolution')
306    search_parser.add_argument('--severity',
307                               action='append',
308                               help='restrict by severity (one or more)')
309    search_parser.add_argument('-s', '--status',
310                               action='append',
311                               dest='search_statuses',
312                               help='restrict by status '
313                               '(one or more, use all for all statuses)')
314    search_parser.add_argument('-v', '--version',
315                               action='append',
316                               help='restrict by version (one or more)')
317    search_parser.add_argument('-w', '--whiteboard',
318                               help='status whiteboard')
319    search_parser.add_argument('--show-status',
320                               action='store_true',
321                               help='show status of bugs')
322    search_parser.add_argument('--show-priority',
323                               action='store_true',
324                               help='show priority of bugs')
325    search_parser.add_argument('--show-severity',
326                               action='store_true',
327                               help='show severity of bugs')
328    search_parser.set_defaults(func=bugz.cli.search)
329
330    return parser
331