Skip to content

Commit

Permalink
cmd/export: update command that exports the statemachine docs
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Feb 1, 2024
1 parent 253d3f0 commit c5786c7
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

bconsts "github.com/bmc-toolbox/bmclib/v2/constants"
sw "github.com/filanov/stateswitch"
"github.com/metal-toolbox/flasher/internal/model"
"github.com/metal-toolbox/flasher/internal/outofband"
sm "github.com/metal-toolbox/flasher/internal/statemachine"
"github.com/spf13/cobra"

"github.com/emicklei/dot"
Expand Down Expand Up @@ -58,29 +58,18 @@ func asGraph(s *sw.StateMachineJSON) *dot.Graph {
}

func taskStateMachine() {
handler := &sm.MockTaskHandler{}

m, err := sm.NewTaskStateMachine(handler)
if err != nil {
log.Fatal(err)
}

j, err := m.DescribeAsJSON()
if err != nil {
log.Fatal(err)
}
g := dot.NewGraph(dot.Directed)

if exportFlagSet.json {
fmt.Println(string(j))
os.Exit(0)
}
pending := g.Node(string(model.StatePending))
active := g.Node(string(model.StateActive))
succeeded := g.Node(string(model.StateSucceeded))
failed := g.Node(string(model.StateFailed))

t := &sw.StateMachineJSON{}
if err := json.Unmarshal(j, t); err != nil {
log.Fatal(err)
}
g.Edge(pending, active, "Task active")
g.Edge(active, succeeded, "Task successful")
g.Edge(active, failed, "Task failed")

fmt.Println(dot.MermaidGraph(asGraph(t), dot.MermaidTopDown))
fmt.Println(dot.MermaidGraph(g, dot.MermaidTopDown))
}

func outofbandActionStatemachine() {
Expand Down Expand Up @@ -115,6 +104,7 @@ func outofbandActionStatemachine() {
func exportStatemachine() {
if exportFlagSet.taskSM {
taskStateMachine()

return
}

Expand Down

0 comments on commit c5786c7

Please sign in to comment.