davidovich / summon

Summon: your data on caffeine
Apache License 2.0
12 stars 0 forks source link

feature: support dynamic completions and delegation #67

Closed davidovich closed 2 years ago

davidovich commented 4 years ago

Allow calling into a user defined completion program (including self references).

This will require changing the format of the invocables to allow further customizations (help, completion hook, cmd etc.)

A design will follow.

Dynamic completion from cobra:

https://github.com/spf13/cobra/blob/master/shell_completions.md#customizing-completions

davidovich commented 3 years ago

Example config file changes, additions:

  manifest2:
    help: 'render kubernetes manifests in build dir'
    cmdArgs: [*baseargs, 'manifests/{{arg 0 "manifest"}}','{{ template "parseArgs" 1 }}']
    completion: '{{ summon "make list-environments" }}'

  build2:
    help: 'build components'
    cmdArgs: &build2 [*baseargs, 'build/{{arg 0 "build"}}','{{ flag "--config-root"}}']
    args:
      - image:
          cmdArgs: [*baseargs, 'build/image/{{arg 0 "build image"}}']
          help: "build images in this repo"
          completion: '{{ summon "make to-do-implement-image-list" }}'

      - gitlab-ci.yaml:
          flags:
            --one-pipeline: '{{ if eq . "true"}} PARENT_CHILD=0 {{ else }} PARENT_CHILD=1'
          cmdArgs: [*build2, '{{ flag "--one-pipeline" }}']
          help: "Initialize or merge gitlab-ci.yaml"

      # call internal helper to complete the generic target list
      - '{{ summon "make list-build-targets" }}'

flags:
  --config-root: 'CONFIG_ROOT=.'

This supposes the following changes: