From 95dde11d68ad36813ed306a25eb1d351dfe45b0d Mon Sep 17 00:00:00 2001 From: Jose Gil Date: Mon, 16 Sep 2019 10:58:28 +0200 Subject: [PATCH 1/4] Allowing to change the output file name from wire_gen.go to other --- internal/wire/wire.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/wire/wire.go b/internal/wire/wire.go index 1b64de02..790f9f41 100644 --- a/internal/wire/wire.go +++ b/internal/wire/wire.go @@ -63,7 +63,8 @@ func (gen GenerateResult) Commit() error { // GenerateOptions holds options for Generate. type GenerateOptions struct { // Header will be inserted at the start of each generated file. - Header []byte + Header []byte + OutputFile string } // Generate performs dependency injection for the packages that match the given @@ -94,7 +95,7 @@ func Generate(ctx context.Context, wd string, env []string, patterns []string, o generated[i].Errs = append(generated[i].Errs, err) continue } - generated[i].OutputPath = filepath.Join(outDir, "wire_gen.go") + generated[i].OutputPath = filepath.Join(outDir, opts.OutputFile) g := newGen(pkg) injectorFiles, errs := generateInjectors(g, pkg) if len(errs) > 0 { From ca395e0a954a4be765946b0ee30cdddf8f2b8e7f Mon Sep 17 00:00:00 2001 From: Jose Gil Date: Mon, 16 Sep 2019 12:07:22 +0200 Subject: [PATCH 2/4] cmd changed --- cmd/wire/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/wire/main.go b/cmd/wire/main.go index c607b90f..f8d8328e 100644 --- a/cmd/wire/main.go +++ b/cmd/wire/main.go @@ -98,7 +98,8 @@ func newGenerateOptions(headerFile string) (*wire.GenerateOptions, error) { } type genCmd struct { - headerFile string + headerFile string + outputFileName string } func (*genCmd) Name() string { return "gen" } @@ -115,6 +116,7 @@ func (*genCmd) Usage() string { } func (cmd *genCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&cmd.headerFile, "header_file", "", "path to file to insert as a header in wire_gen.go") + f.StringVar(&cmd.outputFileName, "output_file", "", "change the output default file 'wire_gen.go' for a custom name.") } func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { @@ -128,6 +130,11 @@ func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa log.Println(err) return subcommands.ExitFailure } + opts.OutputFile = "wire_gen.go" + if cmd.outputFileName != "" { + opts.OutputFile = cmd.outputFileName + } + outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts) if len(errs) > 0 { logErrors(errs) @@ -200,6 +207,7 @@ func (cmd *diffCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interf log.Println(err) return subcommands.ExitFailure } + outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts) if len(errs) > 0 { logErrors(errs) From 154f5ccd08875d8d1db2f33e6de46e133f0e18f6 Mon Sep 17 00:00:00 2001 From: Jose Gil Date: Mon, 23 Sep 2019 14:52:12 +0200 Subject: [PATCH 3/4] Fixed unnecessary if statement for set prefix and changed to prefix for generated wire_gen files --- cmd/wire/main.go | 10 ++++------ internal/wire/wire.go | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/wire/main.go b/cmd/wire/main.go index f8d8328e..3526d18f 100644 --- a/cmd/wire/main.go +++ b/cmd/wire/main.go @@ -99,7 +99,7 @@ func newGenerateOptions(headerFile string) (*wire.GenerateOptions, error) { type genCmd struct { headerFile string - outputFileName string + prefixFileName string } func (*genCmd) Name() string { return "gen" } @@ -116,7 +116,7 @@ func (*genCmd) Usage() string { } func (cmd *genCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&cmd.headerFile, "header_file", "", "path to file to insert as a header in wire_gen.go") - f.StringVar(&cmd.outputFileName, "output_file", "", "change the output default file 'wire_gen.go' for a custom name.") + f.StringVar(&cmd.prefixFileName, "prefix", "", "prefix to the output files concat with 'wire_gen.go' suffix.") } func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { @@ -130,10 +130,8 @@ func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa log.Println(err) return subcommands.ExitFailure } - opts.OutputFile = "wire_gen.go" - if cmd.outputFileName != "" { - opts.OutputFile = cmd.outputFileName - } + + opts.PrefixOutputFile = cmd.prefixFileName outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts) if len(errs) > 0 { diff --git a/internal/wire/wire.go b/internal/wire/wire.go index 790f9f41..10069a49 100644 --- a/internal/wire/wire.go +++ b/internal/wire/wire.go @@ -63,8 +63,8 @@ func (gen GenerateResult) Commit() error { // GenerateOptions holds options for Generate. type GenerateOptions struct { // Header will be inserted at the start of each generated file. - Header []byte - OutputFile string + Header []byte + PrefixOutputFile string } // Generate performs dependency injection for the packages that match the given @@ -95,7 +95,7 @@ func Generate(ctx context.Context, wd string, env []string, patterns []string, o generated[i].Errs = append(generated[i].Errs, err) continue } - generated[i].OutputPath = filepath.Join(outDir, opts.OutputFile) + generated[i].OutputPath = filepath.Join(outDir, opts.PrefixOutputFile+"wire_gen.go") g := newGen(pkg) injectorFiles, errs := generateInjectors(g, pkg) if len(errs) > 0 { From ceb3c3f663d9c995612bf6d2a3152efc2b02285d Mon Sep 17 00:00:00 2001 From: Jose Gil Date: Wed, 25 Sep 2019 08:42:31 +0200 Subject: [PATCH 4/4] Changing input name and description from pull request suggestions --- cmd/wire/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/wire/main.go b/cmd/wire/main.go index 3526d18f..36c06e98 100644 --- a/cmd/wire/main.go +++ b/cmd/wire/main.go @@ -116,7 +116,7 @@ func (*genCmd) Usage() string { } func (cmd *genCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&cmd.headerFile, "header_file", "", "path to file to insert as a header in wire_gen.go") - f.StringVar(&cmd.prefixFileName, "prefix", "", "prefix to the output files concat with 'wire_gen.go' suffix.") + f.StringVar(&cmd.prefixFileName, "output_file_prefix", "", "string to prepend to output file names.") } func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {