Skip to content

Commit 1cbdb3d

Browse files
committed
fopen: add flag -q to suppress stdout from external command
pass twice to also suppress stderr
1 parent de4e2dd commit 1cbdb3d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

stig/commands/base/file.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,21 @@ class FOpenCmdbase(metaclass=CommandMeta):
183183
'fileopen "that torrent" *.mkv mpv'
184184
'fileopen "that torrent" *.mkv mpv --fullscreen',)
185185
argspecs = (
186+
{'names': ('--quiet', '-q'),
187+
'description': 'Suppress stdout from the external command. Pass twice to also suppress stderr',
188+
'action': 'count', 'default': 0},
186189
make_X_FILTER_spec('TORRENT', or_focused=True, nargs='?'),
187190
make_X_FILTER_spec('FILE', or_focused=True, nargs='?'),
188-
{"names": ('COMMAND',),
189-
'description': "Command to use to open files. Default: xdg-open",
191+
{'names': ('COMMAND',),
192+
'description': 'Command to use to open files. Default: xdg-open',
190193
'nargs': '?'
191194
},
192-
{"names": ('OPTS',),
195+
{'names': ('OPTS',),
193196
'description': "Options for the external command.",
194197
'nargs': 'REMAINDER'
195198
},
196199
)
197-
async def run(self, TORRENT_FILTER, FILE_FILTER, COMMAND, OPTS):
200+
async def run(self, quiet, TORRENT_FILTER, FILE_FILTER, COMMAND, OPTS):
198201
default_command = 'xdg-open'
199202
if COMMAND is None:
200203
command = default_command
@@ -244,7 +247,11 @@ def closepipes(proc):
244247

245248
# TODO separate options for stdout/stderr
246249
stdoutlogger = lambda s: self.info(command + ": " + s)
250+
if quiet >= 1:
251+
stdoutlogger = lambda s: None
247252
stderrlogger = lambda s: self.error(command + ": " + s)
253+
if quiet >= 2:
254+
stderrlogger = lambda s: None
248255
loop = asyncio.get_running_loop()
249256
try:
250257
if command == default_command:

stig/commands/tui/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ class FOpenCmd(base.FOpenCmdbase, mixin.make_request, mixin.select_torrents, mix
3535
# When files are selected in the tui, the two first arguments, the torrent
3636
# and the file(s) need to be filled in. That is, `fopen mpv` should mean
3737
# `fopen torrent file mpv`
38-
async def run(self, COMMAND, TORRENT_FILTER, FILE_FILTER, OPTS):
39-
await base.FOpenCmdbase.run(self, TORRENT_FILTER=COMMAND, FILE_FILTER=FILE_FILTER, COMMAND=TORRENT_FILTER, OPTS=OPTS)
38+
async def run(self, quiet, COMMAND, TORRENT_FILTER, FILE_FILTER, OPTS):
39+
await base.FOpenCmdbase.run(self, quiet, TORRENT_FILTER=COMMAND, FILE_FILTER=FILE_FILTER, COMMAND=TORRENT_FILTER, OPTS=OPTS)

0 commit comments

Comments
 (0)