Add a mandatory argument to --resources.

It should be use at least with an "all" argument.
Partially fix #49
This commit is contained in:
Johann Dreo 2014-02-02 17:39:28 +01:00
commit 2231cd89bd
2 changed files with 39 additions and 23 deletions

View file

@ -3,7 +3,7 @@ colout(1) -- Color Up Arbitrary Command Output
## SYNOPSIS ## SYNOPSIS
`colout` [-h] [-r] `colout` [-h] [-r RESOURCE]
`colout` [-g] [-c] [-l] [-a] [-t] [-T] [-P] [-s] PATTERN [COLOR(S) [STYLE(S)]] `colout` [-g] [-c] [-l] [-a] [-t] [-T] [-P] [-s] PATTERN [COLOR(S) [STYLE(S)]]
@ -125,10 +125,10 @@ Gentoo
* `-P DIR`, `--palettes-dir DIR`: * `-P DIR`, `--palettes-dir DIR`:
Search for additional palettes (*.gpl files) in this directory. Search for additional palettes (*.gpl files) in this directory.
* `-r`, `--resources`: * `-r TYPE(S)`, `--resources TYPE(S)`:
Print the names of all available colors, styles, themes and palettes. Print the names of available resources. Use a comma-separated list of resources names
A bug currently made it mandatory to use an additional dummy argument to this option (styles, colors, special, themes, palettes, colormaps or lexers),
to make it work correctly, use `-r x`. use 'all' to print everything.
* `-s`, `--source`: * `-s`, `--source`:
Interpret PATTERN as source code readable by the Pygments library. If the first letter of PATTERN Interpret PATTERN as source code readable by the Pygments library. If the first letter of PATTERN

View file

@ -710,7 +710,7 @@ def __args_parse__(argv, usage=""):
parser.add_argument("-c", "--colormap", action="store_true", parser.add_argument("-c", "--colormap", action="store_true",
help="Use the given colors as a colormap (cycle the colors at each match)") help="Use the given colors as a colormap (cycle the colors at each match)")
parser.add_argument("-l", "--scale", parser.add_argument("-l", "--scale", metavar="SCALE",
help="When using the 'scale' colormap, parse matches as decimal numbers (taking your locale into account) \ help="When using the 'scale' colormap, parse matches as decimal numbers (taking your locale into account) \
and apply the rainbow colormap linearly between the given SCALE=min,max") and apply the rainbow colormap linearly between the given SCALE=min,max")
@ -728,8 +728,14 @@ def __args_parse__(argv, usage=""):
parser.add_argument("-P", "--palettes-dir", metavar="DIR", action="append", parser.add_argument("-P", "--palettes-dir", metavar="DIR", action="append",
help="Search for additional palettes (*.gpl files) in this directory") help="Search for additional palettes (*.gpl files) in this directory")
# This normally should be an option with an argument, but this would end in an error,
# as no regexp is supposed to be passed after calling this option,
# we use it as the argument to this option.
# The only drawback is that the help message lacks a metavar...
parser.add_argument("-r", "--resources", action="store_true", parser.add_argument("-r", "--resources", action="store_true",
help="Print the names of all available colors, styles, themes and palettes.") help="Print the names of available resources. Use a comma-separated list of resources names \
(styles, colors, special, themes, palettes, colormaps or lexers), \
use 'all' to print everything.")
parser.add_argument("--debug", action="store_true", parser.add_argument("--debug", action="store_true",
help="Debug mode: print what's going on internally, useful if you want to check what features are available.") help="Debug mode: print what's going on internally, useful if you want to check what features are available.")
@ -827,25 +833,35 @@ if __name__ == "__main__":
sys.exit( error_codes["DuplicatedPalette"] ) sys.exit( error_codes["DuplicatedPalette"] )
if resources: if resources:
print("Available resources:") asked=[r.lower() for r in pattern.split(",")]
print("STYLES: %s" % ", ".join(styles) ) # print("Available resources:")
print("COLORS: %s" % ", ".join(colors) ) for res in asked:
print("SPECIAL: %s" % ", ".join(["random", "Random", "scale", "Scale", "hash", "Hash", "colormap"]) ) if "style" in res or "all" in res:
print("STYLES: %s" % ", ".join(styles) )
if len(themes) > 0: if "color" in res or "all" in res:
print("THEMES: %s" % ", ".join(themes.keys()) ) print("COLORS: %s" % ", ".join(colors) )
else:
print("NO THEME")
if len(colormaps) > 0: if "special" in res or "all" in res:
print("COLORMAPS: %s" % ", ".join(colormaps) ) print("SPECIAL: %s" % ", ".join(["random", "Random", "scale", "Scale", "hash", "Hash", "colormap"]) )
else:
print("NO COLORMAPS")
if len(lexers) > 0: if "theme" in res or "all" in res:
print("LEXERS: %s" % ", ".join(lexers) ) if len(themes) > 0:
else: print("THEMES: %s" % ", ".join(themes.keys()) )
print("NO LEXER") else:
print("NO THEME")
if "colormap" in res or "all" in res:
if len(colormaps) > 0:
print("COLORMAPS: %s" % ", ".join(colormaps) )
else:
print("NO COLORMAPS")
if "lexer" in res or "all" in res:
if len(lexers) > 0:
print("LEXERS: %s" % ", ".join(lexers) )
else:
print("NO LEXER")
sys.exit(0) # not an error, we asked for help sys.exit(0) # not an error, we asked for help