cmd: Add --output_file_prefix, which sets a prefix for the output file name "wire_gen.go"
This commit is contained in:
committed by
Robert van Gent
parent
c385f07c5d
commit
55a93fac11
@@ -98,7 +98,8 @@ func newGenerateOptions(headerFile string) (*wire.GenerateOptions, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type genCmd struct {
|
type genCmd struct {
|
||||||
headerFile string
|
headerFile string
|
||||||
|
prefixFileName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*genCmd) Name() string { return "gen" }
|
func (*genCmd) Name() string { return "gen" }
|
||||||
@@ -115,6 +116,7 @@ func (*genCmd) Usage() string {
|
|||||||
}
|
}
|
||||||
func (cmd *genCmd) SetFlags(f *flag.FlagSet) {
|
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.headerFile, "header_file", "", "path to file to insert as a header in wire_gen.go")
|
||||||
|
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 {
|
func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
|
||||||
@@ -128,6 +130,9 @@ func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return subcommands.ExitFailure
|
return subcommands.ExitFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts.PrefixOutputFile = cmd.prefixFileName
|
||||||
|
|
||||||
outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)
|
outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
logErrors(errs)
|
logErrors(errs)
|
||||||
@@ -200,6 +205,7 @@ func (cmd *diffCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interf
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return subcommands.ExitFailure
|
return subcommands.ExitFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)
|
outs, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
logErrors(errs)
|
logErrors(errs)
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ func (gen GenerateResult) Commit() error {
|
|||||||
// GenerateOptions holds options for Generate.
|
// GenerateOptions holds options for Generate.
|
||||||
type GenerateOptions struct {
|
type GenerateOptions struct {
|
||||||
// Header will be inserted at the start of each generated file.
|
// Header will be inserted at the start of each generated file.
|
||||||
Header []byte
|
Header []byte
|
||||||
|
PrefixOutputFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate performs dependency injection for the packages that match the given
|
// 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)
|
generated[i].Errs = append(generated[i].Errs, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
generated[i].OutputPath = filepath.Join(outDir, "wire_gen.go")
|
generated[i].OutputPath = filepath.Join(outDir, opts.PrefixOutputFile+"wire_gen.go")
|
||||||
g := newGen(pkg)
|
g := newGen(pkg)
|
||||||
injectorFiles, errs := generateInjectors(g, pkg)
|
injectorFiles, errs := generateInjectors(g, pkg)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user