Skip to content

Add uses: keyword for YAML composition #252

@diegolovison

Description

@diegolovison

Currently, to compose multiple configuration files or override specific state variables from a base configuration, the user must provide all files as command-line arguments in a specific order.

For example, if I want semeru25.yaml to take priority over (and extend) semeru.yaml, I currently have to execute the command like this:

jbang qDup@hyperfoil -b /tmp semeru25.yaml semeru.yaml

This approach has a few downsides:

  1. Command Complexity: As configurations grow, the CLI command becomes verbose and prone to ordering errors.
  2. Implicit Dependencies: The entry point file (semeru25.yaml) does not explicitly state that it relies on semeru.yaml. A user must "just know" to include the base file in the CLI arguments for the script to function correctly.

Describe the solution you'd like

I would like to introduce a uses: keyword (or similar, like import or include) within the YAML definition itself. This allows a specific YAML file to explicitly define its base dependencies.

When qDup processes a file with uses:, it should load the referenced file(s) first, and then overlay the current file's configuration on top of it. This ensures the current file maintains priority (overrides) for variables and state.

Proposed Syntax Example

File: semeru.yaml (The Base)

scripts:
  my-script:
    - sh: echo "I am the base script"
STATE:
  VERSION: "1.0"

File: semeru25.yaml (The Implementation)

# Proposed new keyword
uses: semeru.yaml

# This file's definitions should take priority/merge with the used file
STATE:
  VERSION: "2.5" 

Expected Behavior

Running the command with just the single entry file:

jbang qDup@hyperfoil -b /tmp semeru25.yaml

should automatically detect the uses directive, load semeru.yaml in the background, and result in a merged configuration where VERSION is 2.5.

Additional Context

The uses keyword should support a list of files to allow for multiple layers of composition.

Precedence Rule:
The processing order should follow the list sequence, where the last file in the uses list takes precedence over the first. The current file (the one defining uses) takes priority over everything in the list.

Example:

uses:
  - base.yaml
  - middle.yaml

In this scenario:

  1. base.yaml is loaded.
  2. middle.yaml is loaded and overrides base.yaml.
  3. The current file is loaded and overrides middle.yaml.

This feature moves dependency management from "execution time" (CLI args) to "definition time" (YAML), making scripts more self-contained, portable, and easier to share.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions