Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: target aliases and matrix generation #675

Closed
ghostsquad opened this issue Feb 20, 2022 · 1 comment
Closed

Feature: target aliases and matrix generation #675

ghostsquad opened this issue Feb 20, 2022 · 1 comment

Comments

@ghostsquad
Copy link
Contributor

This is a continuation of #268 and #340 - It appears the conversation abruptly ended without conclusion.

Describe in detail what feature do you want to see in Task.

Given a task file such as:

version: 3

tasks:
  install:
    cmds:
      - yarn install

I'd like to be able to do something like task i. Since i can with 100% confidence resolve to install since there are no other tasks that start with i, it could be automatically aliased without the need to force the user to define aliases.

Even though in this situation it feels fluid and expected, the following scenario may end up with suboptimal alias names:

version: 3

tasks:
  get:serviceham:
    cmds:
      - ./serviceham.sh
  get:serviceaccount:
    cmds:
      - kubectl -n hello get serviceaccount {{ .CLI_ARGS }}
  get:service:
     cmds:
       - kubectl -n hello get service {{ .CLI_ARGS }}

aliases generated

task get:service
task get:servicea

In this particular case, since service is a strict substring of serviceaccount, This may surprising, especially in the case when new tasks are added to the file that the user was not aware of, and they were used to using this alias functionality. E.G. if task get:service was what the user was used to running that resolved in get:serviceaccount, and later get:service was added, all of a sudden the alias get:service is no longer and alias, but a target. I feel this is dangerous.

One way to resolve this is to give the footgun to the user, such that it's their responsibility to create aliases that could not be ambiguous:

tasks:
  get:serviceham:
    aliases:
    - gsh
    cmds:
      - ./serviceham.sh
  get:serviceaccount:
    aliases:
    - gsa
    cmds:
      - kubectl -n hello get serviceaccount {{ .CLI_ARGS }}
  get:service:
    aliases:
    - gsvc
     cmds:
       - kubectl -n hello get service {{ .CLI_ARGS }}

In addition to supporting manually managed aliases, it maybe be interesting to programmatically generate tasks & aliases similar to https://github.com/ahmetb/kubectl-aliases?ts=4#syntax-explanation

tasks:
  kubectl:
    aliases:
      - k
    cmds:
      - kubectl {{ .MATRIX.command }} {{ .MATRIX.resource }} {{ .MATRIX.outputformat }} {{ .MATRIX.namespace }}  {{ .CLI_ARGS }}
    matrix:
       command:
          g: "get"
       resource:
          po: "pod"
       outputformat:
          "": ""
          oyaml: "-o yaml"
          ojson: "-o json"
          owide: "-o wide"
       namespace:
          "": ""
          all: "--all-namespaces"
          mine: "--namespace mine"

The ordering of how the groups are used in the cmds would inform how the alias is created (if it's possible to figure it out from there or not)

To be honest, the matrix part of this may be related, but since both features could be used in conjection, the matrix could be moved to a separate issue/feature.

@pd93
Copy link
Member

pd93 commented Oct 15, 2022

Since aliases are now a merged in #879, this can be closed. If there is still a desire for the matrix functionality described, I feel this should be logged as a new ticket.

Though, I will add that these kind of command shortcuts are very subjective to individuals and I don't feel that they really fit Task. They seem better suited to a user's shell aliases instead.

@pd93 pd93 closed this as completed Oct 15, 2022
@pd93 pd93 removed the v4 label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants