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
`colout` [-h] [-r]
`colout` [-h] [-r RESOURCE]
`colout` [-g] [-c] [-l] [-a] [-t] [-T] [-P] [-s] PATTERN [COLOR(S) [STYLE(S)]]
@ -125,10 +125,10 @@ Gentoo
* `-P DIR`, `--palettes-dir DIR`:
Search for additional palettes (*.gpl files) in this directory.
* `-r`, `--resources`:
Print the names of all available colors, styles, themes and palettes.
A bug currently made it mandatory to use an additional dummy argument to this option
to make it work correctly, use `-r x`.
* `-r TYPE(S)`, `--resources TYPE(S)`:
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.
* `-s`, `--source`:
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",
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) \
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",
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",
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",
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"] )
if resources:
print("Available resources:")
print("STYLES: %s" % ", ".join(styles) )
print("COLORS: %s" % ", ".join(colors) )
print("SPECIAL: %s" % ", ".join(["random", "Random", "scale", "Scale", "hash", "Hash", "colormap"]) )
asked=[r.lower() for r in pattern.split(",")]
# print("Available resources:")
for res in asked:
if "style" in res or "all" in res:
print("STYLES: %s" % ", ".join(styles) )
if len(themes) > 0:
print("THEMES: %s" % ", ".join(themes.keys()) )
else:
print("NO THEME")
if "color" in res or "all" in res:
print("COLORS: %s" % ", ".join(colors) )
if len(colormaps) > 0:
print("COLORMAPS: %s" % ", ".join(colormaps) )
else:
print("NO COLORMAPS")
if "special" in res or "all" in res:
print("SPECIAL: %s" % ", ".join(["random", "Random", "scale", "Scale", "hash", "Hash", "colormap"]) )
if len(lexers) > 0:
print("LEXERS: %s" % ", ".join(lexers) )
else:
print("NO LEXER")
if "theme" in res or "all" in res:
if len(themes) > 0:
print("THEMES: %s" % ", ".join(themes.keys()) )
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