Skip to content

Commit

Permalink
[save] fix confirm message on commit #2090
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Nov 1, 2023
1 parent c7260df commit 3129820
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion visidata/loaders/eml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def extract_part(sheet, givenpath, part):
@EmailSheet.api
def extract_parts(sheet, givenpath, *parts):
'Save all *parts* to Path *givenpath*.'
vd.confirmOverwrite(givenpath)
vd.confirmOverwrite(givenpath, f'{givenpath} already exists, extract anyway?')

vd.status('saving %s parts to %s' % (len(parts), givenpath.given))

Expand Down
7 changes: 4 additions & 3 deletions visidata/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def couldOverwrite(vd) -> bool:


@VisiData.api
def confirmOverwrite(vd, path, cstr='overwrite'):
def confirmOverwrite(vd, path, msg:str=''):
'Fail if file exists and overwrite not allowed.'
if path.exists():
msg = msg or f'{givenpath} exists. overwrite? '
ow = vd.options.overwrite
if ow.startswith('c'): # confirm
vd.confirm(f"{path.given} already exists. {cstr}? ")
vd.confirm(msg)
elif ow.startswith('y'): # yes/always
pass
else: #1805 empty/no/never/readonly
Expand Down Expand Up @@ -318,7 +319,7 @@ def commit(sheet, *rows):
adds, mods, deletes = sheet.getDeferredChanges()
cstr = sheet.changestr(adds, mods, deletes)

vd.confirmOverwrite(sheet.rootSheet().source, cstr)
vd.confirmOverwrite(sheet.rootSheet().source, 'really ' + cstr + '? ')

sheet.putChanges()
sheet.hasBeenModified = False
Expand Down

0 comments on commit 3129820

Please sign in to comment.