[activator] add --color option, see bug #2381

This commit is contained in:
Fabio Erculiani
2011-04-29 17:13:27 +02:00
parent 43a07fce71
commit ffb7c9dd17
3 changed files with 19 additions and 8 deletions

View File

@@ -33,6 +33,10 @@ print version
disable colorized output
=item B<--color>
force colorized output
=back
=head1 OPTIONS

View File

@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "ACTIVATOR 1"
.TH ACTIVATOR 1 "2011-02-07" "perl v5.12.2" "Entropy"
.TH ACTIVATOR 1 "2011-04-29" "perl v5.12.2" "Entropy"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -155,6 +155,9 @@ print version
.IP "\fB\-\-nocolor\fR" 4
.IX Item "--nocolor"
disable colorized output
.IP "\fB\-\-color\fR" 4
.IX Item "--color"
force colorized output
.SH "OPTIONS"
.IX Header "OPTIONS"
.IP "\fBsync\fR" 4
@@ -282,6 +285,6 @@ Fabio Erculiani <lxnay@sabayon.org>
.SH "POD ERRORS"
.IX Header "POD ERRORS"
Hey! \fBThe above document had some coding errors, which are explained below:\fR
.IP "Around line 184:" 4
.IX Item "Around line 184:"
.IP "Around line 188:" 4
.IX Item "Around line 188:"
You forgot a '=back' before '=head1'

View File

@@ -29,10 +29,6 @@ from text_tools import print_menu
def get_entropy_server():
return Server(community_repo = etpConst['community']['mode'])
# Check if we need to disable colors
if not is_stdout_a_tty():
nocolor()
help_opts = [
None,
(0, " ~ activator ~ ", 1,
@@ -43,6 +39,7 @@ help_opts = [
(1, '--help', 2, _('this output')),
(1, '--version', 1, _('print version')),
(1, '--nocolor', 1, _('disable colorized output')),
(1, '--color', 2, _('force colorized output')),
None,
(0, _('Application Options'), 0, None),
None,
@@ -113,9 +110,12 @@ for n in range(len(options)):
# preliminary options parsing
_options = []
force_color = False
for opt in options:
if opt == "--nocolor":
if opt in ["--nocolor", "-N"]:
nocolor()
elif opt in ["--color", "-C"]:
force_color = True
elif opt in ["--quiet", "-q"]:
etpUi['quiet'] = True
elif opt in ["--verbose", "-v"]:
@@ -128,6 +128,10 @@ for opt in options:
_options.append(opt)
options = _options
# Check if we need to disable colors
if (not force_color) and (not is_stdout_a_tty()):
nocolor()
# print help
if not options or ("--help" in options) or ("-h" in options):
print_menu(help_opts)