From def9a01dc60da9e45dcaa1f0a9e17cc455e9813b Mon Sep 17 00:00:00 2001 From: Yulian Kuncheff Date: Thu, 16 Feb 2023 11:55:44 -0800 Subject: [PATCH] Output Aliases when running `mage -l` --- mage/import_test.go | 3 +++ mage/template.go | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/mage/import_test.go b/mage/import_test.go index 83949b27..5adc8974 100644 --- a/mage/import_test.go +++ b/mage/import_test.go @@ -28,6 +28,9 @@ Targets: zz:buildSubdir2 Builds stuff. zz:ns:deploy2* deploys stuff. +Aliases: + nsd2 -> zz:ns:deploy2 + * default target `[1:] diff --git a/mage/template.go b/mage/template.go index af822f0f..83a1c102 100644 --- a/mage/template.go +++ b/mage/template.go @@ -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) @@ -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 {