Skip to content

Commit

Permalink
add optional alphebatical sorting as CLI arg
Browse files Browse the repository at this point in the history
  • Loading branch information
alehechka committed Jul 4, 2022
1 parent 642d446 commit 2725d3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 17 additions & 10 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
)

const (
urlFlag = "url"
fileFlag = "file"
rootFlag = "root"
packageFlag = "package"
outputFileFlag = "output"
debugFlag = "debug"
quietFlag = "quiet"
stdoutFlag = "out"
timeFormatFlag = "time"
omitEmptyFlag = "omitempty"
urlFlag = "url"
fileFlag = "file"
rootFlag = "root"
packageFlag = "package"
outputFileFlag = "output"
debugFlag = "debug"
quietFlag = "quiet"
stdoutFlag = "out"
timeFormatFlag = "time"
omitEmptyFlag = "omitempty"
alphabeticalFlag = "alphabetical"
)

var generateFlags = []cli.Flag{
Expand Down Expand Up @@ -62,6 +63,11 @@ var generateFlags = []cli.Flag{
Name: omitEmptyFlag,
Usage: "Appends the omitempty to all object variable tags.",
},
&cli.BoolFlag{
Name: alphabeticalFlag,
Aliases: []string{"a", "alpha"},
Usage: "Sorts all keys into alphabetical order before generation.",
},
&cli.BoolFlag{
Name: debugFlag,
Usage: "Log debug messages.",
Expand Down Expand Up @@ -93,6 +99,7 @@ func generateTypes(ctx *cli.Context) (err error) {
OutputFileName: ctx.String(outputFileFlag),
TimeFormat: ctx.String(timeFormatFlag),
OmitEmpty: ctx.Bool(omitEmptyFlag),
Alphabetical: ctx.Bool(alphabeticalFlag),
}

if ctx.Bool(stdoutFlag) {
Expand Down
2 changes: 2 additions & 0 deletions gen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Config struct {
OutputFileName string
TimeFormat string
OmitEmpty bool
Alphabetical bool
}

func (c *Config) toJensharedConfig() *jenshared.Config {
Expand All @@ -39,6 +40,7 @@ func (c *Config) toJensharedConfig() *jenshared.Config {
OutputDirectory: dir,
TimeFormat: c.getTimeFormat(),
OmitEmpty: c.OmitEmpty,
Alphabetical: c.Alphabetical,
Debugger: c.Debugger,
}
}
Expand Down

0 comments on commit 2725d3c

Please sign in to comment.