Command aliases
Closed this issue · 4 comments
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.
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
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
Wow. concernedly:
- Proposal about bash
pre
scripts - I strongly support this feature `cause it provides much more flexible functionality; - 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
Implemented before
directive (similar to gitlab ci before_script
)