mirror of
https://github.com/cheat/cheat.git
synced 2024-12-18 18:55:06 +01:00
22b64d2d08
Resolving merge-conflicts.
81 lines
1.8 KiB
Python
Executable File
81 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
"""cheat
|
|
|
|
Create and view cheatsheets on the command line.
|
|
|
|
Usage:
|
|
cheat <cheatsheet>
|
|
cheat -e <cheatsheet>
|
|
cheat -s <keyword>
|
|
cheat -l
|
|
cheat -d
|
|
cheat -v
|
|
|
|
Options:
|
|
-d --directories List directories on CHEATPATH
|
|
-e --edit Edit cheatsheet
|
|
-l --list List cheatsheets
|
|
-s --search Search cheatsheets for <keyword>
|
|
-v --version Print the version number
|
|
|
|
Examples:
|
|
|
|
To view the `tar` cheatsheet:
|
|
cheat tar
|
|
|
|
To edit (or create) the `foo` cheatsheet:
|
|
cheat -e foo
|
|
|
|
To list all available cheatsheets:
|
|
cheat -l
|
|
|
|
To search for "ssh" among all cheatsheets:
|
|
cheat -s ssh
|
|
"""
|
|
|
|
# require the dependencies
|
|
from __future__ import print_function
|
|
from cheat import sheets, sheet
|
|
from cheat.utils import colorize
|
|
from cheat.utils import die
|
|
from docopt import docopt
|
|
import os
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# validate CHEAT_HIGHLIGHT values if set
|
|
colors = [
|
|
'grey' , 'red' , 'green' , 'yellow' ,
|
|
'blue' , 'magenta' , 'cyan' , 'white' ,
|
|
]
|
|
if (
|
|
os.environ.get('CHEAT_HIGHLIGHT') and
|
|
os.environ.get('CHEAT_HIGHLIGHT') not in colors
|
|
):
|
|
die("%s %s" %('CHEAT_HIGHLIGHT must be one of:', colors))
|
|
|
|
# parse the command-line options
|
|
options = docopt(__doc__, version='cheat 2.3.1')
|
|
|
|
# list directories
|
|
if options['--directories']:
|
|
print("\n".join(sheets.paths()))
|
|
|
|
# list cheatsheets
|
|
elif options['--list']:
|
|
print(sheets.list(), end="")
|
|
|
|
# create/edit cheatsheet
|
|
elif options['--edit']:
|
|
sheet.create_or_edit(options['<cheatsheet>'])
|
|
|
|
# search among the cheatsheets
|
|
elif options['--search']:
|
|
print(colorize(sheets.search(options['<keyword>'])), end="")
|
|
|
|
# print the cheatsheet
|
|
else:
|
|
print(colorize(sheet.read(options['<cheatsheet>'])), end="")
|