Skip to content

Commit

Permalink
[sheet-] in execCommand(), fail if cmd does not exist
Browse files Browse the repository at this point in the history
During replay, if a command does not exist, failing is safer
than warning. A nonexistent command could be caused by a typo
in a user-edited command log, or previously user-defined commands
that no longer exist.
  • Loading branch information
midichef committed Jul 1, 2024
1 parent 2d9d052 commit 5612b77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion visidata/basesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def execCommand(self, longname, vdglobals=None, keystrokes=None):

cmd = self.getCommand(longname or keystrokes)
if not cmd:
vd.warning('no command for %s' % (longname or keystrokes))
vd.fail('no command for %s' % (longname or keystrokes))
return False

escaped = False
Expand Down
4 changes: 4 additions & 0 deletions visidata/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def runOneTest(self, mock_screen, longname):

sample_file = vd.pkg_resources_files(visidata) / 'tests/sample.tsv'
vs = visidata.TsvSheet('test_commands', source=visidata.Path(sample_file))
cmd = vs.getCommand(longname)
if not cmd:
vd.warning(f'command cannot be tested on TsvSheet, skipping: {longname}')
return
vs.reload.__wrapped__(vs)
vs.vd = vd
vd.sheets = [vs]
Expand Down

0 comments on commit 5612b77

Please sign in to comment.