|
| 1 | +from __future__ import print_function |
| 2 | + |
1 | 3 | import argparse |
2 | 4 | from jenkins import JenkinsException |
3 | 5 |
|
4 | 6 | from jenkins_cli.cli import JenkinsCli, CliException, get_jobs_legend |
| 7 | +from jenkins_cli.version import version |
5 | 8 |
|
6 | 9 |
|
7 | 10 | def main(): |
8 | 11 | parser = argparse.ArgumentParser(prog='jenkins', |
9 | | - description='Server URL, Username and password may be specified either by the command line arguments ' |
10 | | - 'or in configuration file (.jenkins-cli). Command line arguments has the highest priority, ' |
11 | | - 'after that the .jenkins-cli file from current folder is taking into account. If there is no' |
12 | | - '.jenkins-cli file in current folder, setiings will be read from .jenkins-cli from the home' |
| 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' |
13 | 16 | 'folder') |
14 | | - parser.add_argument('--host', metavar='jenkins-url', help='Jenkins Server Url', default=None) |
| 17 | + parser.add_argument('--host', metavar='jenkins-url', help='Jenkins Host', default=None) |
15 | 18 | parser.add_argument('--username', metavar='username', help='Jenkins Username', default=None) |
16 | 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) |
17 | 21 |
|
18 | 22 | subparsers = parser.add_subparsers(title='Available commands', dest='jenkins_command') |
19 | 23 |
|
20 | 24 | jobs_parser = subparsers.add_parser('jobs', |
21 | 25 | help='Show all jobs and their statuses', |
22 | 26 | formatter_class=argparse.RawTextHelpFormatter, |
23 | 27 | description="Status description:\n\n" + "\n".join(get_jobs_legend())) |
24 | | - jobs_parser.add_argument('-a', help='Show only active jobs', default=False, action='store_true') |
| 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') |
25 | 30 |
|
26 | | - subparsers.add_parser('queue', help='Shows builds queue') |
| 31 | + subparsers.add_parser('queue', help='Show builds queue') |
27 | 32 |
|
28 | 33 | subparsers.add_parser('building', help='Build executor status') |
29 | 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 | + |
30 | 38 | start_parser = subparsers.add_parser('start', help='Start job') |
31 | 39 | start_parser.add_argument('job_name', help='Job to start', nargs='*') |
32 | 40 |
|
33 | 41 | start_parser = subparsers.add_parser('info', help='Job info') |
34 | | - start_parser.add_argument('job_name', help='Job to to get info for') |
| 42 | + start_parser.add_argument('job_name', help='Job to get info for') |
35 | 43 |
|
36 | | - set_branch = subparsers.add_parser('setbranch', help='Set SCM branch') |
37 | | - set_branch.add_argument('job_name', help='Job to to set branch') |
38 | | - set_branch.add_argument('branch_name', help='Name of the SCM branch') |
| 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') |
39 | 47 |
|
40 | 48 | stop_parser = subparsers.add_parser('stop', help='Stop job') |
41 | 49 | stop_parser.add_argument('job_name', help='Job to stop') |
42 | 50 |
|
43 | | - console_parser = subparsers.add_parser('console', help='Show console for last build') |
| 51 | + console_parser = subparsers.add_parser('console', help='Show console for the build') |
44 | 52 | console_parser.add_argument('job_name', help='Job to show console for') |
45 | | - console_parser.add_argument('-n', help='Show first n num of the lines only(if n is negative, shows last n lines)', type=int) |
46 | | - console_parser.add_argument('-i', help='Interactive console', default=False, action='store_true') |
| 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 | + |
| 57 | + console_parser = subparsers.add_parser('changes', help="Show build's changes") |
| 58 | + console_parser.add_argument('job_name', help='Job to show changes for') |
| 59 | + console_parser.add_argument('-b', '--build', help='job build number to show changes for (if omitted, last build number is used)', default='') |
47 | 60 |
|
48 | 61 | args = parser.parse_args() |
49 | 62 | try: |
50 | | - JenkinsCli(args).run_command(args) |
| 63 | + if args.jenkins_command is None: |
| 64 | + parser.print_help() |
| 65 | + else: |
| 66 | + JenkinsCli(args).run_command(args) |
51 | 67 | except JenkinsException as e: |
52 | | - print(e) |
| 68 | + print("Jenkins server response: %s:" % e) |
53 | 69 | except KeyboardInterrupt: |
54 | 70 | print("Aborted") |
55 | 71 | except CliException as e: |
|
0 commit comments