mirror of https://github.com/cheat/cheat.git
Revert Print back to main, would be easier to integrate other positional option like that
This commit is contained in:
parent
1e1520ce56
commit
a0cfee02d2
41
cheat
41
cheat
|
@ -158,26 +158,6 @@ def main():
|
||||||
edit_cheatsheet(values[0], cheatsheets)
|
edit_cheatsheet(values[0], cheatsheets)
|
||||||
parser.exit()
|
parser.exit()
|
||||||
|
|
||||||
# print the cheatsheet if it exists
|
|
||||||
class PrintSheet(argparse.Action):
|
|
||||||
def __call__(self, parser, namespace, value, option_string=None):
|
|
||||||
if not value or value in ['help', 'cheat']:
|
|
||||||
parser.print_help()
|
|
||||||
elif value in cheatsheets:
|
|
||||||
filename = os.path.join(cheatsheets[value], value)
|
|
||||||
if USE_PYGMENTS:
|
|
||||||
pretty_print(filename)
|
|
||||||
else:
|
|
||||||
with open(filename) as istream:
|
|
||||||
for l in istream:
|
|
||||||
sys.stdout.write(l)
|
|
||||||
|
|
||||||
# if it does not, say so
|
|
||||||
else:
|
|
||||||
print >> sys.stderr, ('No cheatsheet found for %s.' % value)
|
|
||||||
parser.exit(1)
|
|
||||||
parser.exit()
|
|
||||||
|
|
||||||
desc = dedent('''
|
desc = dedent('''
|
||||||
cheat allows you to create and view interactive cheatsheets on the
|
cheat allows you to create and view interactive cheatsheets on the
|
||||||
command-line. It was designed to help remind *nix system
|
command-line. It was designed to help remind *nix system
|
||||||
|
@ -205,7 +185,7 @@ def main():
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
parser_group = parser.add_mutually_exclusive_group()
|
parser_group = parser.add_mutually_exclusive_group()
|
||||||
parser_group.add_argument('sheet', metavar='cheatsheet',
|
parser_group.add_argument('sheet', metavar='cheatsheet',
|
||||||
action=PrintSheet, type=str, nargs='?',
|
action='store', type=str, nargs='?',
|
||||||
help='Look at <cheatseet>')
|
help='Look at <cheatseet>')
|
||||||
parser_group.add_argument('-c', '--create', metavar='cheatsheet',
|
parser_group.add_argument('-c', '--create', metavar='cheatsheet',
|
||||||
action=EditSheet, type=str, nargs=1,
|
action=EditSheet, type=str, nargs=1,
|
||||||
|
@ -220,6 +200,25 @@ def main():
|
||||||
action=ListDirectories, nargs=0,
|
action=ListDirectories, nargs=0,
|
||||||
help='List all current cheat dirs')
|
help='List all current cheat dirs')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
sheet = args.sheet
|
||||||
|
|
||||||
|
# Print the cheatsheet if it exists
|
||||||
|
if not sheet or sheet in ['help', 'cheat']:
|
||||||
|
parser.print_help()
|
||||||
|
elif sheet in cheatsheets:
|
||||||
|
filename = os.path.join(cheatsheets[sheet], sheet)
|
||||||
|
if USE_PYGMENTS:
|
||||||
|
pretty_print(filename)
|
||||||
|
else:
|
||||||
|
with open(filename) as istream:
|
||||||
|
for l in istream:
|
||||||
|
sys.stdout.write(l)
|
||||||
|
|
||||||
|
# if it does not, say so
|
||||||
|
else:
|
||||||
|
print >> sys.stderr, ('No cheatsheet found for %s.' % sheet)
|
||||||
|
exit(1)
|
||||||
|
exit()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue