Skip to content

Commit

Permalink
Merge pull request #20 from Enrico204/add-sort-switch
Browse files Browse the repository at this point in the history
Add `-s` switch to enable collection sorting
  • Loading branch information
thedevsaddam committed Aug 7, 2019
2 parents d489338 + 2bb13f5 commit 0c6067e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var (
in string
out string
isMarkdown bool
sortEnabled bool
buildOutput = &cobra.Command{
Use: "build",
Short: "Build html/markdown documentation from postman collection",
Expand All @@ -17,6 +18,7 @@ var (
)

func init() {
buildOutput.PersistentFlags().BoolVarP(&sortEnabled, "sort", "s", false, "sort the collection list")
buildOutput.PersistentFlags().StringVarP(&in, "in", "i", "", "postman collection file relative path")
buildOutput.PersistentFlags().StringVarP(&out, "out", "o", "", "output file relative path")
buildOutput.PersistentFlags().BoolVarP(&isMarkdown, "md", "m", false, "this flag will command to generate markdown")
Expand Down
4 changes: 3 additions & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func (r *Root) Open(rdr io.Reader) error {
return err
}
r.build()
r.sortCollections()
if sortEnabled {
r.sortCollections()
}

r.removeEmptyCollections()

Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,8 @@ func readJSONtoMarkdownHTML(str string) *bytes.Buffer {
return buf
}
func main() {
cmd.Execute()
err := cmd.Execute()
if err != nil {
panic(err)
}
}
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
serveLive.PersistentFlags().IntVarP(&port, "port", "p", 9000, "port number to listen")
serveLive.PersistentFlags().StringVarP(&file, "file", "f", "", "postman collection file's relative path")
serveLive.PersistentFlags().BoolVarP(&isMarkdown, "md", "m", false, "display markdown format in preview")
serveLive.PersistentFlags().BoolVarP(&sortEnabled, "sort", "s", false, "sort the collection list")
}

func server(cmd *cobra.Command, args []string) {
Expand Down

0 comments on commit 0c6067e

Please sign in to comment.