Skip to content

Commit 8ffce6f

Browse files
committed
#3 update help messages
1 parent b7b859d commit 8ffce6f

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ Server URL, Username and password may be specified either by the command line ar
3232
# Available commands:
3333
```bash
3434
{jobs,queue,building,start,info,set_branch,stop,console}
35-
jobs Show all jobs and their status
35+
jobs Show all jobs and their statuses
3636
queue Shows builds queue
3737
building Build executor status
3838
start Start job
3939
info Job info
40-
set_branch Job info
40+
set_branch Set SCM branch
4141
stop Stop job
42-
console Show job history
42+
console Show console for last build
4343
```

jenkins_cli/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
from jenkins import JenkinsException
33

4-
from jenkins_cli.cli import JenkinsCli, CliException
4+
from jenkins_cli.cli import JenkinsCli, CliException, get_jobs_legend
55

66

77
def main():
@@ -17,7 +17,10 @@ def main():
1717

1818
subparsers = parser.add_subparsers(title='Available commands', dest='jenkins_command')
1919

20-
jobs_parser = subparsers.add_parser('jobs', help='Show all jobs and their status')
20+
jobs_parser = subparsers.add_parser('jobs',
21+
help='Show all jobs and their statuses',
22+
formatter_class=argparse.RawTextHelpFormatter,
23+
description="Status description:\n\n" + "\n".join(get_jobs_legend()))
2124
jobs_parser.add_argument('-a', help='Show only active jobs', default=False, action='store_true')
2225

2326
subparsers.add_parser('queue', help='Shows builds queue')
@@ -30,15 +33,15 @@ def main():
3033
start_parser = subparsers.add_parser('info', help='Job info')
3134
start_parser.add_argument('job_name', help='Job to to get info for')
3235

33-
set_branch = subparsers.add_parser('set_branch', help='Job info')
36+
set_branch = subparsers.add_parser('setbranch', help='Set SCM branch')
3437
set_branch.add_argument('job_name', help='Job to to set branch')
35-
set_branch.add_argument('branch_name', help='Name of the branch')
38+
set_branch.add_argument('branch_name', help='Name of the SCM branch')
3639

3740
stop_parser = subparsers.add_parser('stop', help='Stop job')
3841
stop_parser.add_argument('job_name', help='Job to stop')
3942

40-
console_parser = subparsers.add_parser('console', help='Show job history')
41-
console_parser.add_argument('job_name', help='Job to show history for')
43+
console_parser = subparsers.add_parser('console', help='Show console for last build')
44+
console_parser.add_argument('job_name', help='Job to show console for')
4245
console_parser.add_argument('-n', help='Show first n num of the lines only(if n is negative, shows last n lines)', type=int)
4346
console_parser.add_argument('-i', help='Interactive console', default=False, action='store_true')
4447

jenkins_cli/cli.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
from xml.etree import ElementTree
88

99
STATUSES = {'blue': {'symbol': 'S',
10-
'color': '\033[94m'},
10+
'color': '\033[94m',
11+
'descr': 'Stable'},
1112
'red': {'symbol': 'F',
12-
'color': '\033[91m'},
13+
'color': '\033[91m',
14+
'descr': 'Failed'},
1315
'yellow': {'symbol': 'U',
14-
'color': '\033[93m'},
16+
'color': '\033[93m',
17+
'descr': 'Unstable'},
1518
'disabled': {'symbol': 'D',
16-
'color': '\033[97m'},
19+
'color': '\033[97m',
20+
'descr': 'Disabled'},
1721
'aborted': {'symbol': 'A',
18-
'color': '\033[97m'}
22+
'color': '\033[97m',
23+
'descr': 'Aborted'}
1924
}
2025

2126
# 'green': '\033[92m',
@@ -25,6 +30,25 @@
2530
ANIME_SYMBOL = ['..', '>>']
2631

2732

33+
def get_formated_status(job_color, format_pattern="%(color)s%(symbol)s%(run_status)s%(endcollor)s"):
34+
color_status = job_color.split('_')
35+
color = color_status[0]
36+
run_status = color_status[1] if len(color_status) == 2 else None
37+
status = STATUSES[color]
38+
return format_pattern % {'color': status['color'],
39+
'symbol': status['symbol'],
40+
'descr': status['descr'],
41+
'run_status': ANIME_SYMBOL[run_status == 'anime'],
42+
'endcollor': ENDCOLLOR}
43+
44+
45+
def get_jobs_legend():
46+
pattern = "%(color)s%(symbol)s..%(endcollor)s -> %(descr)s"
47+
legend = [get_formated_status(job_color, pattern) for job_color in STATUSES.keys()]
48+
legend.append(".>> -> Build in progress")
49+
return legend
50+
51+
2852
class CliException(Exception):
2953
pass
3054

@@ -84,11 +108,8 @@ def run_command(self, args):
84108
def jobs(self, args):
85109
jobs = self._get_jobs(args)
86110
for job in jobs:
87-
color_status = job['color'].split('_')
88-
color = color_status[0]
89-
run_status = color_status[1] if len(color_status) == 2 else None
90-
status = STATUSES[color]
91-
print("%s%s%s%s %s" % (status['color'], status['symbol'], ANIME_SYMBOL[run_status == 'anime'], ENDCOLLOR, job['name']))
111+
formated_status = get_formated_status(job['color'])
112+
print(formated_status + " " + job['name'])
92113

93114
def _get_jobs(self, args):
94115
jobs = self.jenkins.get_jobs()

0 commit comments

Comments
 (0)