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

Command aliases #81

Closed
xXxRisingTidexXx opened this issue Jun 18, 2020 · 4 comments
Closed

Command aliases #81

xXxRisingTidexXx opened this issue Jun 18, 2020 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@xXxRisingTidexXx
Copy link

It's quite a nice feature to have an opportunity to make command aliases/command prefix shortcuts. Sometimes lets.yaml may look like this:

shell: bash
commands:
  compile:
    description: Compilation
    cmd: docker run --rm -v ${PWD}:/go/src/app helloworld sh -c "go build -o helloworld main.go"
  format:
    description: Formatting
    cmd: docker run --rm -v ${PWD}:/go/src/app helloworld sh -c "gofmt -w -s ."
  test:
    description: Testing
    cmd: docker run --rm -v ${PWD}:/go/src/app helloworld sh -c "go test"
  lint:
    description: Linting
    cmd: docker run --rm -v ${PWD}:/go/src/app helloworld sh -c "golangci-lint run"
  run:
    description: Execution
    cmd: ./helloworld

In this case command shortcuts would shorten general commands' length, like this:

shell: bash
aliases:
  docker: docker run --rm -v ${PWD}:/go/src/app helloworld
commands:
  compile:
    description: Compilation
    cmd: @docker go build -o helloworld main.go
  format:
    description: Formatting
    cmd: @docker gofmt -w -s .
  test:
    description: Testing
    cmd: @docker go test
  lint:
    description: Linting
    cmd: @docker golangci-lint run
  run:
    description: Execution
    cmd: ./helloworld

Character @ or % or some other one can be used as a placeholder identifier.

@kindermax
Copy link
Collaborator

kindermax commented Jun 21, 2020

Hi, I like this idea. Is seems like @ identifier can be safely used as an accessor to aliases.

Also, I have another idea to reach the same result.
We can basically have some kind of pre command (just like before-script in gitlab-ci.yaml).
What it does is just execute some bash (sh) before an actual command so the result is accessible from actual cmd.

How it might look like:

shell: bash

before: |
  function my_docker() {
    docker run --rm -v ${PWD}:/go/src/app helloworld "$@"
  }

commands:
  run:
    cmd: my_docker go test

But, as I can tell, its a bit different from an aliases idea. Its rather a bash script including.

Anyway, aliases seem ok and feels like it solves the problem

@kindermax kindermax added enhancement New feature or request good first issue Good for newcomers labels Jun 21, 2020
@kindermax
Copy link
Collaborator

Also, I was thinking about an alias field for a command. It could help with migrations from old to new commands. Just thinking if it's wouldn't interfere with aliases global directive

commands:
  old-run:
    alias: run
    cmd: node app.js

@xXxRisingTidexXx
Copy link
Author

Wow. concernedly:

  1. Proposal about bash pre scripts - I strongly support this feature `cause it provides much more flexible functionality;
  2. Directive alias: maybe, it would be even a better idea to allow multiple aliases? Like:
commands:
  upgrade:
    cmd: alembic upgrade head
    aliases:
      - migrate
      - apply
      - up

kindermax added a commit that referenced this issue Sep 24, 2020
kindermax added a commit that referenced this issue Sep 24, 2020
kindermax added a commit that referenced this issue Sep 24, 2020
kindermax added a commit that referenced this issue Sep 24, 2020
kindermax added a commit that referenced this issue Sep 24, 2020
@kindermax
Copy link
Collaborator

Implemented before directive (similar to gitlab ci before_script)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants