diff --git a/build.go b/build.go index 92c8eae..53cde71 100644 --- a/build.go +++ b/build.go @@ -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", @@ -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") diff --git a/collection.go b/collection.go index 3c55e12..1aafc6d 100644 --- a/collection.go +++ b/collection.go @@ -119,7 +119,9 @@ func (r *Root) Open(rdr io.Reader) error { return err } r.build() - r.sortCollections() + if sortEnabled { + r.sortCollections() + } r.removeEmptyCollections() diff --git a/main.go b/main.go index 87129e5..53587fa 100644 --- a/main.go +++ b/main.go @@ -189,5 +189,8 @@ func readJSONtoMarkdownHTML(str string) *bytes.Buffer { return buf } func main() { - cmd.Execute() + err := cmd.Execute() + if err != nil { + panic(err) + } } diff --git a/server.go b/server.go index 9f064ab..05a3691 100644 --- a/server.go +++ b/server.go @@ -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) {