|
1 | 1 | from __future__ import print_function |
2 | 2 |
|
3 | | -import argparse |
4 | 3 | from jenkins import JenkinsException |
5 | 4 |
|
6 | | -from jenkins_cli.cli import JenkinsCli, CliException, get_jobs_legend, check_nonnegative |
7 | | -from jenkins_cli.version import version |
| 5 | +from jenkins_cli.cli import JenkinsCli, CliException |
| 6 | +from jenkins_cli.cli_arguments import load_parser |
8 | 7 |
|
9 | 8 |
|
10 | 9 | def main(): |
11 | | - parser = argparse.ArgumentParser(prog='jenkins', |
12 | | - description='Host, username and password may be specified either by the command line arguments ' |
13 | | - 'or in the configuration file (.jenkins-cli). Command line arguments have the highest priority, ' |
14 | | - 'after that the .jenkins-cli file from current folder is used. If there is no' |
15 | | - '.jenkins-cli file in the current folder, settings will be read from .jenkins-cli located in the home' |
16 | | - 'folder') |
17 | | - parser.add_argument('--host', metavar='jenkins-url', help='Jenkins Host', default=None) |
18 | | - parser.add_argument('--username', metavar='username', help='Jenkins Username', default=None) |
19 | | - parser.add_argument('--password', metavar='password', help='Jenkins Password', default=None) |
20 | | - parser.add_argument('--version', '-v', action='version', version='jenkins-cli %s' % version) |
21 | | - |
22 | | - subparsers = parser.add_subparsers(title='Available commands', dest='jenkins_command') |
23 | | - |
24 | | - jobs_parser = subparsers.add_parser('jobs', |
25 | | - help='Show all jobs and their statuses', |
26 | | - formatter_class=argparse.RawTextHelpFormatter, |
27 | | - description="Status description:\n\n" + "\n".join(get_jobs_legend())) |
28 | | - jobs_parser.add_argument('-a', help='show only active jobs', default=False, action='store_true') |
29 | | - jobs_parser.add_argument('-p', help='show only jobs in build progress', default=False, action='store_true') |
30 | | - |
31 | | - subparsers.add_parser('queue', help='Show builds queue') |
32 | | - |
33 | | - subparsers.add_parser('building', help='Build executor status') |
34 | | - |
35 | | - builds_parser = subparsers.add_parser('builds', help='Show builds for the job') |
36 | | - builds_parser.add_argument('job_name', help='Job name of the builds') |
37 | | - |
38 | | - start_parser = subparsers.add_parser('start', help='Start job') |
39 | | - start_parser.add_argument('job_name', help='Job to start', nargs='*') |
40 | | - |
41 | | - start_parser = subparsers.add_parser('info', help='Job info') |
42 | | - start_parser.add_argument('job_name', help='Job to get info for') |
43 | | - |
44 | | - set_branch = subparsers.add_parser('setbranch', help='Set VCS branch (Mercurial or Git)') |
45 | | - set_branch.add_argument('job_name', help='Job to set branch for') |
46 | | - set_branch.add_argument('branch_name', help='Name of the VCS branch') |
47 | | - |
48 | | - stop_parser = subparsers.add_parser('stop', help='Stop job') |
49 | | - stop_parser.add_argument('job_name', help='Job to stop') |
50 | | - |
51 | | - console_parser = subparsers.add_parser('console', help='Show console for the build') |
52 | | - console_parser.add_argument('job_name', help='Job to show console for') |
53 | | - console_parser.add_argument('-b', '--build', help='job build number to show console for (if omitted, last build number is used)', default='') |
54 | | - console_parser.add_argument('-n', help='show first n lines only(if n is negative, show last n lines)', type=int) |
55 | | - console_parser.add_argument('-i', help='interactive console', default=False, action='store_true') |
56 | | - console_parser.add_argument('-t', '--interval', help='refresh interval in seconds (in case of interactive console -i)', default=3, type=check_nonnegative) |
57 | | - |
58 | | - console_parser = subparsers.add_parser('changes', help="Show build's changes") |
59 | | - console_parser.add_argument('job_name', help='Job to show changes for') |
60 | | - console_parser.add_argument('-b', '--build', help='job build number to show changes for (if omitted, last build number is used)', default='') |
61 | | - |
| 10 | + parser = load_parser() |
62 | 11 | args = parser.parse_args() |
| 12 | + |
63 | 13 | try: |
64 | 14 | if args.jenkins_command is None: |
65 | 15 | parser.print_help() |
|
0 commit comments