Skip to content

Commit

Permalink
Merge pull request #2 from leozhantw/master
Browse files Browse the repository at this point in the history
feat: add format-json
  • Loading branch information
cloudingcity authored Sep 16, 2020
2 parents 0e9d9ef + 70f62f1 commit bbf2c88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jwt-decode=#
| snake-case | Coverts string to [snake case](https://en.wikipedia.org/wiki/Snake_case) |
| start-case | Coverts string to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage) |
| upper-case | Coverts string to upper case |
| format-json | Cleans and format JSON |

## Library

Expand Down
18 changes: 18 additions & 0 deletions cmd/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/tidwall/pretty"
)

var formatJSONCmd = &cobra.Command{
Use: "format-json [text]",
Short: "Cleans and format JSON",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(string(pretty.Color(pretty.Pretty([]byte(args[0])), nil)))
},
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ func commands() []*cobra.Command {
SnakeCaseCmd,
StartCaseCmd,
UpperCaseCmd,
formatJSONCmd,
}
}

0 comments on commit bbf2c88

Please sign in to comment.