wordfence-cli icon indicating copy to clipboard operation
wordfence-cli copied to clipboard

Any arguments passed before a subcommand are ignored

Open davidnuzik opened this issue 2 years ago • 1 comments

Summary: Any args passed before a subcommand are ignored. For example in the below command the -c arg (pointing to a custom config.ini file location) would be ignored. wordfence -c /tmp/wordfence-cli.ini malware-scan /var/www/wordpress

Workaround: Simply specify any args for a subcommand AFTER that subcommand. For example instead of the above example, it should be executed like as follows: wordfence malware-scan -c /tmp/wordfence-cli.ini /var/www/wordpress Or with -c after the path. The order should not matter as long as the arg (any args) come after the subcommand.

Note: After discussing with Alex, this is how the argparse library we're using works -- as such a fix for this could be fairly involved.


Environment: v2.0.3 release binary on amd64 openSUSE Tumbleweed, kernel 6.6.1-1-default (all environments effected)

Steps to Reproduce:

  1. Try to execute with an arg before a subcommand, such as to supply our -c config file to wordfence: wordfence -c /tmp/wordfence-cli.ini malware-scan /var/www/wordpress

Expected Result: I expected the -c arg to work here, since logically (or logically in my brain with the way I think) the -c arg is for wordfence and the wordpress path is for the malware-scan subcommand.

Actual Result: The -c arg is ignored -- in my case I don't have a default config ini file at ~/.config/wordfence/wordfence-cli.ini and therefore I am prompted to configure for the first time since the arg is ignored.

Additional Info: See the workaround above, just after the "Summary" section. We may want to document this.

I have a couple of ideas in mind as to how we might approach addressing this:

  1. Fix it which could be involved since this isn't how the arg parsing library we use works.
  2. If possible, run a check, if an arg is passed before a subcommand, reject it and ask the user to supply all args after the first subcommand.
  3. Document it (we should probably also if doing #2)

davidnuzik avatar Nov 20 '23 19:11 davidnuzik

Planning for v4.1.0 - provisionally - if this is more difficult/involved then we may move it out to the next release.

davidnuzik avatar Jun 07 '24 18:06 davidnuzik