Skip to content

Commit 33e1cfc

Browse files
committed
fix(gen_viper): specify struct name
1 parent 28535db commit 33e1cfc

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

cmd/add.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var addCmd = &cli.Command{
1010
addTypescriptCmd,
1111
addReactCmd,
1212
addGoAirCmd,
13+
addGoMakefileCmd,
1314
addPriceUpdateConfigCmd,
1415
addViperTagCmd,
1516
},

cmd/add_makefile.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/pot-code/web-cli/pkg/core"
7+
"github.com/pot-code/web-cli/pkg/util"
8+
"github.com/pot-code/web-cli/templates"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
var addGoMakefileCmd = &cli.Command{
13+
Name: "makefile",
14+
Aliases: []string{"m"},
15+
Usage: "add Makefile",
16+
Action: func(c *cli.Context) error {
17+
cmd := addGoMakefile()
18+
return cmd.Run()
19+
},
20+
}
21+
22+
func addGoMakefile() core.Runner {
23+
return util.NewTaskComposer("").AddFile(
24+
&core.FileDesc{
25+
Path: "Makefile",
26+
Data: func() []byte {
27+
var buf bytes.Buffer
28+
29+
templates.WriteGoMakefile(&buf)
30+
return buf.Bytes()
31+
},
32+
},
33+
)
34+
}

cmd/add_viper_tag.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import (
1010

1111
type addViperTagConfig struct {
1212
ConfigPath string `arg:"0" name:"CONFIG_PATH" validate:"required"`
13-
OutName string `name:"out"`
13+
StructName string `name:"struct" validate:"required"`
1414
}
1515

1616
var addViperTagCmd = &cli.Command{
1717
Name: "viper",
1818
Aliases: []string{"v"},
1919
Usage: "generate flags registration go file",
2020
ArgsUsage: "CONFIG_PATH",
21-
Flags: []cli.Flag{
22-
// &cli.StringFlag{
23-
// Name: "out",
24-
// Aliases: []string{"o"},
25-
// Usage: "output file name",
26-
// Value: "config_gen.go",
27-
// },
21+
Flags: []cli.Flag{
22+
&cli.StringFlag{
23+
Name: "struct",
24+
Aliases: []string{"s"},
25+
Usage: "struct name",
26+
Value: "AppConfig",
27+
},
2828
},
2929
Action: func(c *cli.Context) error {
3030
config := new(addViperTagConfig)
@@ -61,7 +61,7 @@ func addViperFlag(config *addViperTagConfig) (core.Runner, error) {
6161
"-file",
6262
config.ConfigPath,
6363
"-struct",
64-
"AppConfig",
64+
config.StructName,
6565
"-add-tags",
6666
"mapstructure,yaml",
6767
},

templates/add_makefile.qtpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% func GoMakefile() -%}
2+
GO:=go
3+
GO_WIN:=GOOS=windows GOARCH=amd64 go
4+
LDFLAGS:=-s -w
5+
BIN_NAME:=app
6+
BIN_NAME_WIN:=app.exe
7+
OUT_PATH:=./.out
8+
9+
build: generate
10+
$(GO) build -ldflags '$(LDFLAGS)' -o $(OUT_PATH)/$(BIN_NAME) .
11+
12+
build-win64: generate
13+
$(GO_WIN) build -ldflags '$(LDFLAGS)' -o $(OUT_PATH)/$(BIN_NAME_WIN) .
14+
15+
generate:
16+
$(GO) generate
17+
{% endfunc -%}

0 commit comments

Comments
 (0)