summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorlshamis <leonid.shamis@gmail.com>2020-10-12 19:26:22 +0200
committerGitHub <noreply@github.com>2020-10-12 19:26:22 +0200
commit644bc2b635f5e6d2e20c654dd43be0554ed33a9d (patch)
treedb1b6c7e4a3ec96a370c7cefb57010d12db03cca /cmd
parentWhen running on Windows the correct path separator must be used (#386) (diff)
downloadforgejo-act-644bc2b635f5e6d2e20c654dd43be0554ed33a9d.tar.xz
forgejo-act-644bc2b635f5e6d2e20c654dd43be0554ed33a9d.zip
Simpler list view (#382)
* Simpler list view * lint * readding graph viz with -g/--graph Co-authored-by: Leonid Shamis <lshamis@bob.localdomain> Co-authored-by: Casey Lee <cplee@nektos.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/list.go57
-rw-r--r--cmd/root.go10
2 files changed, 66 insertions, 1 deletions
diff --git a/cmd/list.go b/cmd/list.go
new file mode 100644
index 0000000..da6e10d
--- /dev/null
+++ b/cmd/list.go
@@ -0,0 +1,57 @@
+package cmd
+
+import (
+ "fmt"
+ "strconv"
+
+ "github.com/nektos/act/pkg/model"
+)
+
+func printList(plan *model.Plan) error {
+ type lineInfoDef struct {
+ id string
+ stage string
+ name string
+ }
+ lineInfos := []lineInfoDef{}
+
+ header := lineInfoDef{
+ id: "ID",
+ stage: "Stage",
+ name: "Name",
+ }
+
+ idMaxWidth := len(header.id)
+ stageMaxWidth := len(header.stage)
+ nameMaxWidth := len(header.name)
+
+ for i, stage := range plan.Stages {
+ for _, r := range stage.Runs {
+ line := lineInfoDef{
+ id: r.JobID,
+ stage: strconv.Itoa(i),
+ name: r.String(),
+ }
+ lineInfos = append(lineInfos, line)
+ if idMaxWidth < len(line.id) {
+ idMaxWidth = len(line.id)
+ }
+ if stageMaxWidth < len(line.stage) {
+ stageMaxWidth = len(line.stage)
+ }
+ if nameMaxWidth < len(line.name) {
+ nameMaxWidth = len(line.name)
+ }
+ }
+ }
+
+ idMaxWidth += 2
+ stageMaxWidth += 2
+ nameMaxWidth += 2
+
+ fmt.Printf("%*s%*s%*s\n", -idMaxWidth, header.id, -stageMaxWidth, header.stage, -nameMaxWidth, header.name)
+ for _, line := range lineInfos {
+ fmt.Printf("%*s%*s%*s\n", -idMaxWidth, line.id, -stageMaxWidth, line.stage, -nameMaxWidth, line.name)
+ }
+ return nil
+}
diff --git a/cmd/root.go b/cmd/root.go
index 2e0b79a..e9e2885 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -34,6 +34,7 @@ func Execute(ctx context.Context, version string) {
}
rootCmd.Flags().BoolP("watch", "w", false, "watch the contents of the local repo and run when files change")
rootCmd.Flags().BoolP("list", "l", false, "list workflows")
+ rootCmd.Flags().BoolP("graph", "g", false, "draw workflows")
rootCmd.Flags().StringP("job", "j", "", "run job")
rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)")
rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)")
@@ -150,10 +151,17 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
plan = planner.PlanEvent(eventName)
}
- // check if we should just print the graph
+ // check if we should just list the workflows
if list, err := cmd.Flags().GetBool("list"); err != nil {
return err
} else if list {
+ return printList(plan)
+ }
+
+ // check if we should just print the graph
+ if list, err := cmd.Flags().GetBool("graph"); err != nil {
+ return err
+ } else if list {
return drawGraph(plan)
}