mirror of
https://github.com/Erreur32/cheat.git
synced 2024-10-31 21:11:07 +01:00
Making some minor code readability changes.
This commit is contained in:
parent
48cdbdd836
commit
1894ce6297
30
cheat
30
cheat
@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
DEFAULT_CHEAT_DIR = os.environ.get('DEFAULT_CHEAT_DIR') or \
|
DEFAULT_CHEAT_DIR = os.environ.get('DEFAULT_CHEAT_DIR') or \
|
||||||
os.path.join(os.path.expanduser('~'), '.cheat')
|
os.path.join(os.path.expanduser('~'), '.cheat')
|
||||||
@ -50,7 +51,7 @@ def cheat_files(cheat_directories):
|
|||||||
|
|
||||||
|
|
||||||
def create_cheatsheet(cheat, cheatsheets):
|
def create_cheatsheet(cheat, cheatsheets):
|
||||||
"Create a new cheatsheet."
|
"Creates a new cheatsheet."
|
||||||
if cheat in cheatsheets:
|
if cheat in cheatsheets:
|
||||||
print ('Cheatsheet "%s" already exists' % cheat)
|
print ('Cheatsheet "%s" already exists' % cheat)
|
||||||
exit()
|
exit()
|
||||||
@ -73,7 +74,7 @@ def create_cheatsheet(cheat, cheatsheets):
|
|||||||
|
|
||||||
|
|
||||||
def edit_cheatsheet(cheat, cheatsheets):
|
def edit_cheatsheet(cheat, cheatsheets):
|
||||||
"Edit a pre-existing cheatsheet."
|
"Edits a pre-existing cheatsheet."
|
||||||
if cheat not in cheatsheets:
|
if cheat not in cheatsheets:
|
||||||
print ('No cheatsheet found for "%s"' % cheat)
|
print ('No cheatsheet found for "%s"' % cheat)
|
||||||
ans = raw_input('Create cheatsheet for "%s" (Y/N)? ' % cheat)
|
ans = raw_input('Create cheatsheet for "%s" (Y/N)? ' % cheat)
|
||||||
@ -122,22 +123,25 @@ def main():
|
|||||||
|
|
||||||
# print help if requested
|
# print help if requested
|
||||||
if keyphrase.lower() in ['', 'cheat', 'help', '-h', '-help', '--help']:
|
if keyphrase.lower() in ['', 'cheat', 'help', '-h', '-help', '--help']:
|
||||||
print ("Usage: cheat [OPTIONS] <keyphrase>")
|
print dedent('''
|
||||||
print ("Examples:\n")
|
Usage: cheat [OPTIONS] <keyphrase>
|
||||||
|
Examples:
|
||||||
|
|
||||||
print ("To look up 'tar':")
|
To look up 'tar':
|
||||||
print ("cheat tar\n")
|
cheat tar
|
||||||
|
|
||||||
print ("To look up 'git commit' (a subcommand):")
|
To look up 'git commit' (a subcommand):
|
||||||
print ("cheat git commit\n")
|
cheat git commit
|
||||||
|
|
||||||
print ("To create a cheatsheet for 'foo':")
|
To create a cheatsheet for 'foo':
|
||||||
print ("cheat -c foo\n")
|
cheat -c foo
|
||||||
|
|
||||||
print ("To edit the cheatsheet for 'foo':")
|
To edit the cheatsheet for 'foo':
|
||||||
print ("cheat -e foo\n")
|
cheat -e foo
|
||||||
|
|
||||||
|
Available keyphrases:
|
||||||
|
''').strip()
|
||||||
|
|
||||||
print ("Available keyphrases:")
|
|
||||||
max_command = max([len(x) for x in cheatsheets.keys()]) + 3
|
max_command = max([len(x) for x in cheatsheets.keys()]) + 3
|
||||||
print ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value)
|
print ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value)
|
||||||
for key, value in cheatsheets.items()])))
|
for key, value in cheatsheets.items()])))
|
||||||
|
Loading…
Reference in New Issue
Block a user