dagger do: list actions at the beginning
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
ae4e61aaa1
commit
e8788cb26b
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -110,34 +111,44 @@ func getTargetPath(args []string) cue.Path {
|
|||||||
func doHelpCmd(cmd *cobra.Command, _ []string) {
|
func doHelpCmd(cmd *cobra.Command, _ []string) {
|
||||||
lg := logger.New()
|
lg := logger.New()
|
||||||
|
|
||||||
fmt.Printf("%s\n\n%s", cmd.Short, cmd.UsageString())
|
fmt.Println(cmd.Short)
|
||||||
|
|
||||||
|
err := printActions(os.Stdout, getTargetPath(cmd.Flags().Args()))
|
||||||
|
|
||||||
|
fmt.Printf("\n%s", cmd.UsageString())
|
||||||
|
|
||||||
p, err := loadPlan()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to load plan")
|
lg.Fatal().Err(err).Msg("failed to load plan")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printActions(w io.Writer, target cue.Path) error {
|
||||||
|
p, err := loadPlan()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
target := getTargetPath(cmd.Flags().Args())
|
|
||||||
action := p.Action().FindByPath(target)
|
action := p.Action().FindByPath(target)
|
||||||
if action == nil {
|
if action == nil {
|
||||||
lg.Fatal().Msg(fmt.Sprintf("action %s not found", target.String()))
|
return fmt.Errorf("action %s not found", target.String())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(action.Name) < 1 {
|
if len(action.Name) < 1 {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\nAvailable Actions:\n")
|
fmt.Printf("\nAvailable Actions:\n")
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.StripEscape)
|
tw := tabwriter.NewWriter(w, 0, 0, 1, ' ', tabwriter.StripEscape)
|
||||||
defer w.Flush()
|
defer tw.Flush()
|
||||||
|
|
||||||
for _, a := range action.Children {
|
for _, a := range action.Children {
|
||||||
if !a.Hidden {
|
if !a.Hidden {
|
||||||
lineParts := []string{"", a.Name, a.Documentation}
|
lineParts := []string{"", a.Name, a.Documentation}
|
||||||
fmt.Fprintln(w, strings.Join(lineParts, "\t"))
|
fmt.Fprintln(tw, strings.Join(lineParts, "\t"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Reference in New Issue
Block a user