Skip to content

Commit 7512e51

Browse files
committed
Use one shared optOutputPath for both API and Controller sub commands
1 parent ada6e82 commit 7512e51

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

cmd/ack-generate/command/apis.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ const (
3535
)
3636

3737
var (
38-
optGenVersion string
39-
optAPIsInputPath string
40-
optAPIsOutputPath string
41-
apisVersionPath string
38+
optGenVersion string
39+
optAPIsInputPath string
40+
apisVersionPath string
4241
)
4342

4443
// apiCmd is the command that generates service API types
@@ -52,9 +51,6 @@ func init() {
5251
apisCmd.PersistentFlags().StringVar(
5352
&optGenVersion, "version", "v1alpha1", "the resource API Version to use when generating API infrastructure and type definitions",
5453
)
55-
apisCmd.PersistentFlags().StringVarP(
56-
&optAPIsOutputPath, "output", "o", "", "path to directory for service controller to create generated files. Defaults to "+optServicesDir+"/$service",
57-
)
5854
rootCmd.AddCommand(apisCmd)
5955
}
6056

@@ -65,8 +61,8 @@ func generateAPIs(cmd *cobra.Command, args []string) error {
6561
return fmt.Errorf("please specify the service alias for the AWS service API to generate")
6662
}
6763
svcAlias := strings.ToLower(args[0])
68-
if optAPIsOutputPath == "" {
69-
optAPIsOutputPath = filepath.Join(optServicesDir, svcAlias)
64+
if optOutputPath == "" {
65+
optOutputPath = filepath.Join(optServicesDir, svcAlias)
7066
}
7167
if err := ensureSDKRepo(optCacheDir); err != nil {
7268
return err
@@ -98,7 +94,7 @@ func generateAPIs(cmd *cobra.Command, args []string) error {
9894
return err
9995
}
10096

101-
apisVersionPath = filepath.Join(optAPIsOutputPath, "apis", optGenVersion)
97+
apisVersionPath = filepath.Join(optOutputPath, "apis", optGenVersion)
10298
for path, contents := range ts.Executed() {
10399
if optDryRun {
104100
fmt.Printf("============================= %s ======================================\n", path)

cmd/ack-generate/command/controller.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ import (
3232
)
3333

3434
var (
35-
optControllerOutputPath string
36-
cmdControllerPath string
37-
pkgResourcePath string
38-
latestAPIVersion string
35+
cmdControllerPath string
36+
pkgResourcePath string
37+
latestAPIVersion string
3938
)
4039

4140
var controllerCmd = &cobra.Command{
@@ -45,9 +44,6 @@ var controllerCmd = &cobra.Command{
4544
}
4645

4746
func init() {
48-
controllerCmd.PersistentFlags().StringVarP(
49-
&optControllerOutputPath, "output", "o", "", "path to root directory to create generated files. Defaults to "+optServicesDir+"/$service",
50-
)
5147
rootCmd.AddCommand(controllerCmd)
5248
}
5349

@@ -57,8 +53,8 @@ func generateController(cmd *cobra.Command, args []string) error {
5753
return fmt.Errorf("please specify the service alias for the AWS service API to generate")
5854
}
5955
svcAlias := strings.ToLower(args[0])
60-
if optControllerOutputPath == "" {
61-
optControllerOutputPath = filepath.Join(optServicesDir, svcAlias)
56+
if optOutputPath == "" {
57+
optOutputPath = filepath.Join(optServicesDir, svcAlias)
6258
}
6359

6460
if err := ensureSDKRepo(optCacheDir); err != nil {
@@ -101,7 +97,7 @@ func generateController(cmd *cobra.Command, args []string) error {
10197
fmt.Println(strings.TrimSpace(contents.String()))
10298
continue
10399
}
104-
outPath := filepath.Join(optControllerOutputPath, path)
100+
outPath := filepath.Join(optOutputPath, path)
105101
outDir := filepath.Dir(outPath)
106102
if _, err := ensureDir(outDir); err != nil {
107103
return err
@@ -117,7 +113,7 @@ func generateController(cmd *cobra.Command, args []string) error {
117113
// latest Kubernetes API version for CRDs exposed by the generated service
118114
// controller.
119115
func getLatestAPIVersion() (string, error) {
120-
apisPath := filepath.Join(optControllerOutputPath, "apis")
116+
apisPath := filepath.Join(optOutputPath, "apis")
121117
versions := []string{}
122118
subdirs, err := ioutil.ReadDir(apisPath)
123119
if err != nil {

cmd/ack-generate/command/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
optDryRun bool
4545
sdkDir string
4646
optGeneratorConfigPath string
47+
optOutputPath string
4748
)
4849

4950
var rootCmd = &cobra.Command{
@@ -113,6 +114,9 @@ func init() {
113114
rootCmd.PersistentFlags().StringVar(
114115
&optGeneratorConfigPath, "generator-config-path", "", "Path to file containing instructions for code generation to use",
115116
)
117+
rootCmd.PersistentFlags().StringVarP(
118+
&optOutputPath, "output", "o", "", "Path to directory to output generated files.",
119+
)
116120
}
117121

118122
// Execute adds all child commands to the root command and sets flags

0 commit comments

Comments
 (0)