mirror of
https://github.com/cheat/cheat.git
synced 2024-11-16 17:08:29 +01:00
928637c9db
Removed unnecessary `import` calls.
79 lines
1.8 KiB
Python
Executable file
79 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.configuration import Configuration
|
|
from cheat.editor import Editor
|
|
from cheat.sheet import Sheet
|
|
from cheat.sheets import Sheets
|
|
from cheat.utils import Utils
|
|
from docopt import docopt
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# parse the command-line options
|
|
options = docopt(__doc__, version='cheat 2.4.2')
|
|
|
|
# initialize and validate configs
|
|
config = Configuration()
|
|
config.validate()
|
|
|
|
# bootsrap
|
|
editor = Editor(config)
|
|
sheets = Sheets(config)
|
|
utils = Utils(config)
|
|
sheet = Sheet(sheets, editor)
|
|
|
|
# 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(utils.colorize(sheets.search(options['<keyword>'])), end="")
|
|
|
|
# print the cheatsheet
|
|
else:
|
|
print(utils.colorize(sheet.read(options['<cheatsheet>'])), end="")
|