Skip to content

[Feature] Support Selecting Properties in jsonInputArg objects. #1265

@EmperorArthur

Description

@EmperorArthur

Summary of the new feature / enhancement

Provide a method of passing individual properties as arguments instead of the entire JSON.

This supports more complex scenarios, and splitting behavior already exists when using "input": "env".

Reasoning

In creating a Pip resource I found myself wishing I could pass in just the "name" property as an argument. While the resource would not be as feature rich, combined with #1261 and #1264 I could have created a resource using only the definition and without needing a separate program.

I see a pattern of configuration / package management programs which:

  • Could be resources.
  • Accept strings as arguments, but not JSON.
  • Can output their current state as JSON.

Proposed technical implementation details (optional)

Simple Option

  • Support a property selector allowing for parts of a JSON object to be used as command arguments.
  • Remove the "jsonInputArg" property, as the JSON is always a separate argument as is.
{
        "set": {
            "executable": "python.exe",
            "args": [
                "-m",
                "pip",
                "--no-input",
                "install",
                {
                    "mandatory": true,
                    "property": "name"
                }
            ]
        }
}

More Complex Option

Implement Simple option, and support optional arguments based on a JSON property.

{
        "set": {
            "executable": "python.exe",
            "args": [
                "-m",
                "pip",
                "--no-input",
                "install",
                {
                    "mandatory": false,
                    "property": "useLatest",
                    "type": "switch",
                     args: [ "--upgrade" ]  // Only added if "useLatest" is true.
                },
                {
                    "mandatory": true,
                    "property": "name"
                }
            ]
        }
}
Brainstormed Idea (Out Of Scope) # Most Complex Option (Likely out of scope) * Support [JSON Schema style if then else](https://json-schema.org/understanding-json-schema/reference/conditionals#ifthenelse). * Support a format string, allowing properties to be combined.
{
    "set": {
        "executable": "python.exe",
        "args": [
            "-m",
            "pip",
            "--no-input",
            "install",
            {
               "if": {
                "properties": {
                  "useLatest": { "const": true }
                }
              },
              "then": {
                "args": [
                    "--upgrade"
                ]
              }
            },
            {
               "if": {
                "properties": {
                  "version": { "type": "string" }
                },
                {
                  "required": [ "version" ]
                }
              },
              "then": {
                "args": [
                    { "format": "{name}=={version}" }
                ]
              },
              "else": {
                "args": [
                    { "format": "{name}" }
                ]
              }
            }
        ]
    }
}
</details>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions