2014-04-27 05:31:13 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""cheat
|
|
|
|
|
2017-02-28 05:09:51 +01:00
|
|
|
Create and view cheatsheets on the command line.
|
|
|
|
|
2014-04-27 05:31:13 +02:00
|
|
|
Usage:
|
|
|
|
cheat <cheatsheet>
|
|
|
|
cheat -e <cheatsheet>
|
|
|
|
cheat -s <keyword>
|
|
|
|
cheat -l
|
|
|
|
cheat -d
|
|
|
|
cheat -v
|
|
|
|
|
|
|
|
Options:
|
2019-01-31 23:53:34 +01:00
|
|
|
-d --directories List directories on $CHEAT_PATH
|
2014-04-27 05:31:13 +02:00
|
|
|
-e --edit Edit cheatsheet
|
|
|
|
-l --list List cheatsheets
|
|
|
|
-s --search Search cheatsheets for <keyword>
|
|
|
|
-v --version Print the version number
|
2017-02-28 05:09:51 +01:00
|
|
|
|
|
|
|
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
|
2014-04-27 05:31:13 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# require the dependencies
|
2019-01-11 23:00:39 +01:00
|
|
|
from __future__ import print_function
|
2019-01-31 23:43:21 +01:00
|
|
|
from cheat.colorize import Colorize
|
2019-01-31 23:01:46 +01:00
|
|
|
from cheat.configuration import Configuration
|
|
|
|
from cheat.editor import Editor
|
2018-05-30 08:49:52 +02:00
|
|
|
from cheat.sheet import Sheet
|
2019-01-31 23:01:46 +01:00
|
|
|
from cheat.sheets import Sheets
|
2014-04-27 05:31:13 +02:00
|
|
|
from docopt import docopt
|
|
|
|
|
2015-10-16 00:56:34 +02:00
|
|
|
if __name__ == '__main__':
|
2019-01-11 22:26:57 +01:00
|
|
|
|
2014-04-27 05:31:13 +02:00
|
|
|
# parse the command-line options
|
2019-01-29 17:45:43 +01:00
|
|
|
options = docopt(__doc__, version='cheat 2.4.2')
|
2014-04-27 05:31:13 +02:00
|
|
|
|
2019-01-31 22:45:28 +01:00
|
|
|
# initialize and validate configs
|
2018-05-30 08:49:52 +02:00
|
|
|
config = Configuration()
|
2019-01-31 22:45:28 +01:00
|
|
|
config.validate()
|
|
|
|
|
|
|
|
# bootsrap
|
2019-01-31 23:01:46 +01:00
|
|
|
editor = Editor(config)
|
2019-01-31 23:43:21 +01:00
|
|
|
colorize = Colorize(config)
|
|
|
|
|
|
|
|
sheets = Sheets(config, colorize)
|
2019-01-31 23:14:21 +01:00
|
|
|
sheet = Sheet(sheets, editor)
|
2018-05-30 08:49:52 +02:00
|
|
|
|
2014-04-27 05:31:13 +02:00
|
|
|
# list directories
|
|
|
|
if options['--directories']:
|
|
|
|
print("\n".join(sheets.paths()))
|
|
|
|
|
|
|
|
# list cheatsheets
|
|
|
|
elif options['--list']:
|
2018-06-13 12:56:54 +02:00
|
|
|
print(sheets.list(), end="")
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
# create/edit cheatsheet
|
|
|
|
elif options['--edit']:
|
|
|
|
sheet.create_or_edit(options['<cheatsheet>'])
|
|
|
|
|
|
|
|
# search among the cheatsheets
|
|
|
|
elif options['--search']:
|
2019-01-31 23:43:21 +01:00
|
|
|
print(colorize.syntax(sheets.search(options['<keyword>'])), end="")
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
# print the cheatsheet
|
|
|
|
else:
|
2019-01-31 23:43:21 +01:00
|
|
|
print(colorize.syntax(sheet.read(options['<cheatsheet>'])), end="")
|