From 2725d3c2e5587d6d8c045950aed59727f8abbc4a Mon Sep 17 00:00:00 2001 From: Adam Lehechka <42357034+alehechka@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:16:15 -0500 Subject: [PATCH] add optional alphebatical sorting as CLI arg --- cmd/generate.go | 27 +++++++++++++++++---------- gen/config.go | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 5f0d2a4..62e2164 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -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{ @@ -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.", @@ -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) { diff --git a/gen/config.go b/gen/config.go index ebb8f3b..0643be3 100644 --- a/gen/config.go +++ b/gen/config.go @@ -20,6 +20,7 @@ type Config struct { OutputFileName string TimeFormat string OmitEmpty bool + Alphabetical bool } func (c *Config) toJensharedConfig() *jenshared.Config { @@ -39,6 +40,7 @@ func (c *Config) toJensharedConfig() *jenshared.Config { OutputDirectory: dir, TimeFormat: c.getTimeFormat(), OmitEmpty: c.OmitEmpty, + Alphabetical: c.Alphabetical, Debugger: c.Debugger, } }