make BuildOptions exported

This commit is contained in:
Jingfang Liu
2019-01-07 13:52:52 -08:00
parent a5c6938c65
commit b9ab948ef2
2 changed files with 14 additions and 5 deletions

View File

@@ -29,11 +29,20 @@ import (
"sigs.k8s.io/kustomize/pkg/target" "sigs.k8s.io/kustomize/pkg/target"
) )
type buildOptions struct { // BuildOptions contain the options for running a build
type BuildOptions struct {
kustomizationPath string kustomizationPath string
outputPath string outputPath string
} }
// NewBuildOptions creates a BuildOptions object
func NewBuildOptions(p, o string) *BuildOptions {
return &BuildOptions{
kustomizationPath: p,
outputPath: o,
}
}
var examples = ` var examples = `
Use the file somedir/kustomization.yaml to generate a set of api resources: Use the file somedir/kustomization.yaml to generate a set of api resources:
build somedir build somedir
@@ -54,7 +63,7 @@ func NewCmdBuild(
out io.Writer, fs fs.FileSystem, out io.Writer, fs fs.FileSystem,
rf *resmap.Factory, rf *resmap.Factory,
ptf transformer.Factory) *cobra.Command { ptf transformer.Factory) *cobra.Command {
var o buildOptions var o BuildOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "build [path]", Use: "build [path]",
@@ -77,7 +86,7 @@ func NewCmdBuild(
} }
// Validate validates build command. // Validate validates build command.
func (o *buildOptions) Validate(args []string) error { func (o *BuildOptions) Validate(args []string) error {
if len(args) > 1 { if len(args) > 1 {
return errors.New("specify one path to " + constants.KustomizationFileName) return errors.New("specify one path to " + constants.KustomizationFileName)
} }
@@ -91,7 +100,7 @@ func (o *buildOptions) Validate(args []string) error {
} }
// RunBuild runs build command. // RunBuild runs build command.
func (o *buildOptions) RunBuild( func (o *BuildOptions) RunBuild(
out io.Writer, fSys fs.FileSystem, out io.Writer, fSys fs.FileSystem,
rf *resmap.Factory, ptf transformer.Factory) error { rf *resmap.Factory, ptf transformer.Factory) error {
ldr, err := loader.NewLoader(o.kustomizationPath, fSys) ldr, err := loader.NewLoader(o.kustomizationPath, fSys)

View File

@@ -36,7 +36,7 @@ func TestBuildValidate(t *testing.T) {
"", "specify one path to " + constants.KustomizationFileName}, "", "specify one path to " + constants.KustomizationFileName},
} }
for _, mycase := range cases { for _, mycase := range cases {
opts := buildOptions{} opts := BuildOptions{}
e := opts.Validate(mycase.args) e := opts.Validate(mycase.args)
if len(mycase.erMsg) > 0 { if len(mycase.erMsg) > 0 {
if e == nil { if e == nil {