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

Output Aliases when running mage -l #456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mage/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Targets:
zz:buildSubdir2 Builds stuff.
zz:ns:deploy2* deploys stuff.

Aliases:
nsd2 -> zz:ns:deploy2

* default target
`[1:]

Expand Down
25 changes: 25 additions & 0 deletions mage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ Options:
{{- end}}
}

aliases := map[string]string{
{{- range $k, $v := .Aliases}}
"{{ lowerFirst $k }}": "-> {{lowerFirst $v.TargetName}}",
{{- end}}
}

keys := make([]string, 0, len(targets))
for name := range targets {
keys = append(keys, name)
Expand All @@ -248,6 +254,25 @@ Options:
for _, name := range keys {
_fmt.Fprintf(w, " %v\t%v\n", printName(name), targets[name])
}

if len(aliases) != 0 {
err := w.Flush()
if err != nil {
return err
}

aliasKeys := make([]string, 0, len(aliases))
for name := range aliases {
aliasKeys = append(aliasKeys, name)
}
_sort.Strings(aliasKeys)

_fmt.Println("\nAliases:")
for _, name := range aliasKeys {
_fmt.Fprintf(w, " %v\t%v\n", printName(name), aliases[name])
}
}

err := w.Flush()
{{- if .DefaultFunc.Name}}
if err == nil {
Expand Down