Skip to content

fix: consume the -- separator in every addon argument source - #1

Merged
kfkonrad merged 2 commits into
kfkonrad:kfkonrad/2026-08-24-tvskrvqwqynpfrom
acinader:pr2699-separator-per-source
Sep 3, 2026
Merged

fix: consume the -- separator in every addon argument source#1
kfkonrad merged 2 commits into
kfkonrad:kfkonrad/2026-08-24-tvskrvqwqynpfrom
acinader:pr2699-separator-per-source

Conversation

@acinader

@acinader acinader commented Sep 1, 2026

Copy link
Copy Markdown

Applies on top of plaintextaccounting#2699, against that branch.

plaintextaccounting#2699 applies breakAtFirstSeparator to the command line only, so a -- written
in a config file section or a command alias was not properly processed

[argvdump] section containing "alpha -- beta", run as: hledger --conf CONF argvdump gamma

main            argv: [alpha] [beta] [gamma]
#2699           argv: [alpha] [--] [beta] [gamma]
this PR         argv: [alpha] [beta] [gamma]

It applies to command aliases as well as [COMMAND] sections:

[alias] ad = argvdump -- --x, run as: hledger ad y

main            argv: [--x] [y]
#2699           argv: [--] [--x] [y]
this PR         argv: [--x] [y]

Per source

The sources are joined as
conf <> alias <> cli, so a -- from a config section or alias falls before
the command line args and moves them all into the "after" partition, where
hledger's own options are deliberately not stripped.

argv: [alpha] [beta] [--conf] [CONF] [gamma]

So each source consumes its own first --:

consumeSeparator as = let (bs, cs) = breakAtFirstSeparator as in dropCliSpecificOpts bs <> cs
addonargs = concatMap consumeSeparator
              [supportedgenargsfromconf, confcmdargs0, aliasargs, cliargswithoutcmd]

This also makes the documented -- -n escape hatch reachable from a config
section and from an alias, not only from the command line. Before it, there was
no way to get -n to an addon except by typing it on the command line.

Tests

Three new cases in addons.test cover a config file section, a command alias,
and the escape hatch. A fourth covers an argument containing an apostrophe:
case 13 ("Arguments needing shell quoting are preserved") uses a b and $x,
both of which are delivered literally on main too, so nothing in the suite
currently fails without plaintextaccounting#2699's argv change. An apostrophe is the input that
distinguishes them.

addons.test 17/17, full functional suite 1746/1746, builds warning-free
under -Werror.

Note these cases only run locally for now — all six CI workflows exclude
/addons (see plaintextaccounting#2710).

@kfkonrad not sure if you have notifications on...

AI usage: Claude Opus 5, ~15k output tokens

plaintextaccounting#2699 applies breakAtFirstSeparator to the command line only, so a "--"
written in a config file section or a command alias is passed on to the
addon. main stripped every "--", so it never was.

  [argvdump]
    alpha -- beta

  $ hledger --conf CONF argvdump gamma
  main          argv: [alpha] [beta] [gamma]
  plaintextaccounting#2699         argv: [alpha] [--] [beta] [gamma]
  this commit   argv: [alpha] [beta] [gamma]

Splitting the concatenation once, rather than per source, does not work.
The sources are joined as conf <> alias <> cli, so a "--" from a config
section or alias falls before the command line args and moves them all
into the "after" partition, where hledger's own options are deliberately
not stripped. That leaks them to the addon:

  argv: [alpha] [beta] [--conf] [FILE] [gamma]

So each source consumes its own first "--" instead. That also makes the
documented "-- -n" escape hatch reachable from a config section and from
an alias, not only from the command line.

Cases 14-16 in addons.test cover a config file section, a command alias,
and the escape hatch. addons.test 16/16, full functional suite 1746/1746.

Applies on top of plaintextaccounting#2699, which introduced this.

AI usage: Claude Opus 5, ~15k output tokens
Passing addon arguments as an argv list fixes arguments containing an
apostrophe, which did not reach the addon before this PR.

Case 13 ("Arguments needing shell quoting are preserved") uses 'a b' and
'$x', but both of those are delivered literally on main as well, so it
passes either way. Nothing in the suite currently fails without the argv
change; an apostrophe is the input that distinguishes them.

addons.test 17/17.

AI usage: Claude Opus 5, ~2k output tokens
@acinader
acinader marked this pull request as ready for review September 1, 2026 01:41
@kfkonrad
kfkonrad merged commit 7c7c7cc into kfkonrad:kfkonrad/2026-08-24-tvskrvqwqynp Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants