From 87f1fe13b6a68d766e63145c96976e3934be24bc Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Tue, 30 Jul 2013 23:33:31 -0400 Subject: [PATCH] Cleaned up some python. Added support for subcommands. --- README.md | 5 +++++ cheat | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e6a453d..e1e8df2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ Cheat ===== +- overview +- obligatory xkcd +- examples +- subcommands +- help diff --git a/cheat b/cheat index ecad42b..adec9f6 100755 --- a/cheat +++ b/cheat @@ -4,8 +4,8 @@ import sys # assemble a keyphrase out of all params passed to the script keyphrase = ' '.join(sys.argv[1:]) -# Create a dictionary of cheatsheets -cheats = { +# create a dictionary of cheatsheets +cheatsheets = { 'find' : ''' executable perms @@ -46,13 +46,12 @@ tar -cjvf /path/to/foo.tgz /path/to/foo/ } -# Print help if requested -if keyphrase == 'help' or keyphrase == '--help' or keyphrase == '-h': - print 'Cheatsheets exist for the following keyphrases:' - for key in cheats: +# print help if requested +if keyphrase in ['help', '--help', '-h']: + print 'Available cheatsheets:' + for key in cheatsheets: print key exit() - -# Print the cheatsheet if it exists -print cheats[keyphrase] if keyphrase in cheats.keys() else 'No cheatsheet found.' +# print the cheatsheet if it exists +print cheatsheets[keyphrase] if keyphrase in cheatsheets.keys() else 'No cheatsheet found.'