Skip to content

Support for commands with positional arguments in the File Provisioner  #507

Open
@jmsnll

Description

@jmsnll

What does it concern?

The plugin SDK, design, or schema

Goal or desired behavior

The goal is to address a limitation in the file provisioner of the Provisioner SDK where the current AddArgs function does not handle commands with positional arguments at the end. Such commands cannot accept additional flag arguments after the positional arguments, leading to invalid command construction.

Proposed solution:

  • Replace AddArgs with:
    • PrependArgs: Adds arguments to the beginning of the command (but after the command itself).
    • AppendArgs: Adds arguments to the end of the command, same functionality as the AddArgs function currently.

This change will allow the file provisioner to generate valid commands for age and other CLIs with similar requirements. An argument could be made also for other functionality such as InsertAt(index) or InsertAfter(string) to allow exact placement of the injected argument.

Current behavior

The current implementation of AddArgs appends arguments to the end of the command without considering the position of positional arguments. This leads to issues when commands have strict ordering requirements for flags and positional arguments.

For example, in the file provisioner, consider the age command:

$ age --encrypt --recipients-file key.txt -o output.txt input.txt

In this example:

  • The flag --recipients-file key.txt must appear before the positional argument input.txt
  • Using AddArgs to append these flags results in an invalid command:
$ age --encrypt -o output.txt input.txt --recipients-file key.txt 
age: error: too many INPUT arguments: "input.txt" "--recipients-file" "key.txt"
age: hint: the input file must be specified after all flags
age: hint: did you mean:
age: hint:     age --encrypt -o output.txt --recipients-file key.txt input.txt

Relevant log output

No response

op CLI version

No response

shell-plugins local ref

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions