Skip to content

Commit

Permalink
Allow omitting specified placeholders in custom commands
Browse files Browse the repository at this point in the history
Customizable commands like `--notification-command` require replacement placeholders (`%s` and `%m`). However, it should not be an error to omit either of them.

Ref 1329e23
  • Loading branch information
exquo committed Nov 8, 2021
1 parent d2f437a commit 6cb807d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scli
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def get_urls(txt):

def callf(cmd, rmap=None, background=False, **subprocess_kwargs):
if rmap:
optionals = rmap.pop("_optionals", ())
for key, val in rmap.items():
if key not in cmd:
if key not in cmd and key not in optionals:
raise ValueError(f'Command string `{cmd}` should contain a replacement placeholder `{key}` (e.g. `some-cmd "{key}"`). See `--help`.')
cmd = cmd.replace(key, val)

Expand Down Expand Up @@ -599,7 +600,7 @@ class Daemon(AsyncProc):
try:
proc = callf(
cfg.daemon_command,
{'%u': self._username},
{'%u': self._username, '_optionals': ['%u']},
background=True,
stdout=stdout_fd,
stderr=stderr_fd,
Expand Down Expand Up @@ -3510,6 +3511,7 @@ class Actions:
for token, text in (('%s', sender), ('%m', message)):
text = text.replace(r"'", r"'\''")
rmap[token] = text
rmap['_optionals'] = ('%s', '%m')
self.callf(cfg.notification_command, rmap, background=True)

def send_message_curr_contact(self, message="", attachments=None):
Expand Down

0 comments on commit 6cb807d

Please sign in to comment.