Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #51 from bukalapak/add_list_command
Browse files Browse the repository at this point in the history
Add command to list available path
  • Loading branch information
subosito authored Oct 11, 2018
2 parents 12cfb41 + d847a05 commit d8dba5a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ func main() {
return nil
},
},
{
Name: "list",
Usage: "List available routes",
Action: func(c *cli.Context) error {
if c.Args().Get(0) == "" {
return nil
}
if err := outputPath(c, c.Args()); err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
},
},
{
Name: "mock",
Usage: "Run Mock server",
Expand Down Expand Up @@ -596,6 +609,25 @@ func watchFiles(c *cli.Context, watcher fsWatcher, input, tplFile string) error
return nil
}

func outputPath(c *cli.Context, inputs []string) error {
bs := make([]*api.API, len(inputs))
for i := range inputs {
bp, err := snowboard.Load(inputs[i], engine)
if err != nil {
return err
}

bs[i] = bp
}
ms := mock.MockMulti(bs)
for _, mm := range ms {
for _, m := range mm {
fmt.Fprintf(c.App.Writer, "%s\t%d\t%s\n", m.Method, m.StatusCode, m.Pattern)
}
}
return nil
}

func serveHTML(c *cli.Context, bind, output string) error {
fmt.Fprintf(c.App.Writer, "snowboard: listening on %s\n", bind)

Expand Down

0 comments on commit d8dba5a

Please sign in to comment.