mirror of
https://github.com/cheat/cheat.git
synced 2024-12-18 18:55:06 +01:00
Graceful failure on failed copy to DEFAULT_CHEAT_DIR
Pull request #108 added the option to automatically copy an otherwise-uneditable cheatsheet to your DEFAULT_CHEAT_DIR upon an edit request. This is a minor tweak that implements some graceful failing if the DEFAULT_CHEAT_DIR does not exist.
This commit is contained in:
parent
3234d21654
commit
d8c723681a
10
cheat
10
cheat
@ -123,6 +123,7 @@ class CheatSheets(object):
|
||||
exit(1)
|
||||
else:
|
||||
editor = os.environ['EDITOR'].split()
|
||||
|
||||
# if the cheatsheet already exists, open it for editing
|
||||
try:
|
||||
if cheat in self.sheets:
|
||||
@ -144,10 +145,19 @@ class CheatSheets(object):
|
||||
'again with sudo.')
|
||||
exit(1)
|
||||
import shutil
|
||||
|
||||
# attempt to copy the cheatsheet to DEFAULT_CHEAT_DIR
|
||||
try:
|
||||
new_sheet = os.path.join(DEFAULT_CHEAT_DIR, cheat)
|
||||
shutil.copy(sheet_path, new_sheet)
|
||||
subprocess.call(editor + [new_sheet])
|
||||
|
||||
# fail gracefully if the cheatsheet cannot be copied. This
|
||||
# can happen if DEFAULT_CHEAT_DIR does not exist
|
||||
except IOError:
|
||||
print ('Could not copy cheatsheet for editing.')
|
||||
exit(1)
|
||||
|
||||
# otherwise, create it
|
||||
else:
|
||||
import cheatsheets as cs
|
||||
|
Loading…
Reference in New Issue
Block a user