mirror of
https://github.com/Erreur32/cheat.git
synced 2024-10-31 21:11:07 +01:00
Added main function and wrapped everything in it.
This commit is contained in:
parent
84f3105139
commit
01b35ab0b7
34
cheat
34
cheat
@ -19,21 +19,24 @@ def cheat_files(cheat_directories):
|
||||
for cheat in os.listdir(cheat_dir) if '.' not in cheat ]))
|
||||
return cheats
|
||||
|
||||
# assemble a keyphrase out of all params passed to the script
|
||||
keyphrase = ' '.join(sys.argv[1:])
|
||||
cheat_dirs = cheat_directories()
|
||||
def main():
|
||||
"""MAIN"""
|
||||
|
||||
# verify that we have at least one cheat directory
|
||||
if not cheat_dirs:
|
||||
print >> sys.stderr,\
|
||||
# assemble a keyphrase out of all params passed to the script
|
||||
keyphrase = ' '.join(sys.argv[1:])
|
||||
cheat_dirs = cheat_directories()
|
||||
|
||||
# verify that we have at least one cheat directory
|
||||
if not cheat_dirs:
|
||||
print >> sys.stderr, \
|
||||
'The ~/.cheat dir does not exist or the CHEATPATH var is not set.'
|
||||
exit()
|
||||
|
||||
# list the files in the ~/.cheat directory
|
||||
cheatsheets = cheat_files(cheat_dirs)
|
||||
# list the files in the ~/.cheat directory
|
||||
cheatsheets = cheat_files(cheat_dirs)
|
||||
|
||||
# print help if requested
|
||||
if keyphrase.lower() in ['', 'cheat', 'help', '-h', '-help', '--help']:
|
||||
# print help if requested
|
||||
if keyphrase.lower() in ['', 'cheat', 'help', '-h', '-help', '--help']:
|
||||
print "Usage: cheat [keyphrase]\n"
|
||||
print "Available keyphrases:"
|
||||
max_command = max([ len(x) for x in cheatsheets.keys() ]) + 3
|
||||
@ -41,12 +44,15 @@ if keyphrase.lower() in ['', 'cheat', 'help', '-h', '-help', '--help']:
|
||||
for key, value in cheatsheets.items() ]))
|
||||
exit()
|
||||
|
||||
# print the cheatsheet if it exists
|
||||
if keyphrase in cheatsheets:
|
||||
# print the cheatsheet if it exists
|
||||
if keyphrase in cheatsheets:
|
||||
with open (os.path.join(cheatsheets[keyphrase], keyphrase), 'r')\
|
||||
as cheatsheet:
|
||||
print cheatsheet.read()
|
||||
|
||||
# if it does not, say so
|
||||
else:
|
||||
# if it does not, say so
|
||||
else:
|
||||
print 'No cheatsheet found for %s.' % keyphrase
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user