Skip to content

Commit

Permalink
Add bundle global runtime args
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Nov 18, 2023
1 parent 3e47b18 commit c917324
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
17 changes: 17 additions & 0 deletions cmd/timoni/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@ import (
"github.com/spf13/cobra"
)

type bundleFlags struct {
runtimeFromEnv bool
runtimeFiles []string
runtimeCluster string
runtimeClusterGroup string
}

var bundleArgs bundleFlags

var bundleCmd = &cobra.Command{
Use: "bundle",
Short: "Commands for managing bundles",
}

func init() {
bundleCmd.PersistentFlags().BoolVar(&bundleArgs.runtimeFromEnv, "runtime-from-env", false,
"Inject runtime values from the environment.")
bundleCmd.PersistentFlags().StringSliceVarP(&bundleArgs.runtimeFiles, "runtime", "r", nil,
"The local path to runtime.cue files.")
bundleCmd.PersistentFlags().StringVar(&bundleArgs.runtimeCluster, "runtime-cluster", "*",
"Filter runtime cluster by name.")
bundleCmd.PersistentFlags().StringVar(&bundleArgs.runtimeCluster, "runtime-group", "*",
"Filter runtime clusters by group.")
rootCmd.AddCommand(bundleCmd)
}
12 changes: 3 additions & 9 deletions cmd/timoni/bundle_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ type bundleApplyFlags struct {
wait bool
force bool
overwriteOwnership bool
runtimeFromEnv bool
runtimeFiles []string
creds flags.Credentials
}

Expand All @@ -92,10 +90,6 @@ func init() {
"Perform a server-side apply dry run and prints the diff.")
bundleApplyCmd.Flags().BoolVar(&bundleApplyArgs.wait, "wait", true,
"Wait for the applied Kubernetes objects to become ready.")
bundleApplyCmd.Flags().StringSliceVarP(&bundleApplyArgs.runtimeFiles, "runtime", "r", nil,
"The local path to runtime.cue files.")
bundleApplyCmd.Flags().BoolVar(&bundleApplyArgs.runtimeFromEnv, "runtime-from-env", false,
"Inject runtime values from the environment.")
bundleApplyCmd.Flags().Var(&bundleApplyArgs.creds, bundleApplyArgs.creds.Type(), bundleApplyArgs.creds.Description())
bundleCmd.AddCommand(bundleApplyCmd)
}
Expand Down Expand Up @@ -135,12 +129,12 @@ func runBundleApplyCmd(cmd *cobra.Command, _ []string) error {

runtimeValues := make(map[string]string)

if bundleApplyArgs.runtimeFromEnv {
if bundleArgs.runtimeFromEnv {
maps.Copy(runtimeValues, engine.GetEnv())
}

if len(bundleApplyArgs.runtimeFiles) > 0 {
rt, err := buildRuntime(bundleApplyArgs.runtimeFiles)
if len(bundleArgs.runtimeFiles) > 0 {
rt, err := buildRuntime(bundleArgs.runtimeFiles)
if err != nil {
return err
}
Expand Down
18 changes: 6 additions & 12 deletions cmd/timoni/bundle_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ var bundleBuildCmd = &cobra.Command{
}

type bundleBuildFlags struct {
pkg flags.Package
files []string
creds flags.Credentials
runtimeFromEnv bool
runtimeFiles []string
pkg flags.Package
files []string
creds flags.Credentials
}

var bundleBuildArgs bundleBuildFlags
Expand All @@ -68,10 +66,6 @@ func init() {
bundleBuildCmd.Flags().VarP(&bundleBuildArgs.pkg, bundleBuildArgs.pkg.Type(), bundleBuildArgs.pkg.Shorthand(), bundleBuildArgs.pkg.Description())
bundleBuildCmd.Flags().StringSliceVarP(&bundleBuildArgs.files, "file", "f", nil,
"The local path to bundle.cue files.")
bundleBuildCmd.Flags().BoolVar(&bundleBuildArgs.runtimeFromEnv, "runtime-from-env", false,
"Inject runtime values from the environment.")
bundleBuildCmd.Flags().StringSliceVarP(&bundleBuildArgs.runtimeFiles, "runtime", "r", nil,
"The local path to runtime.cue files.")
bundleBuildCmd.Flags().Var(&bundleBuildArgs.creds, bundleBuildArgs.creds.Type(), bundleBuildArgs.creds.Description())
bundleCmd.AddCommand(bundleBuildCmd)
}
Expand Down Expand Up @@ -107,15 +101,15 @@ func runBundleBuildCmd(cmd *cobra.Command, _ []string) error {

runtimeValues := make(map[string]string)

if bundleBuildArgs.runtimeFromEnv {
if bundleArgs.runtimeFromEnv {
maps.Copy(runtimeValues, engine.GetEnv())
}

if len(bundleBuildArgs.runtimeFiles) > 0 {
if len(bundleArgs.runtimeFiles) > 0 {
kctx, cancel := context.WithTimeout(cmd.Context(), rootArgs.timeout)
defer cancel()

rt, err := buildRuntime(bundleBuildArgs.runtimeFiles)
rt, err := buildRuntime(bundleArgs.runtimeFiles)
if err != nil {
return err
}
Expand Down
18 changes: 6 additions & 12 deletions cmd/timoni/bundle_vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ with Timoni's schema and optionally prints the computed value.
}

type bundleVetFlags struct {
pkg flags.Package
files []string
runtimeFromEnv bool
runtimeFiles []string
printValue bool
pkg flags.Package
files []string
printValue bool
}

var bundleVetArgs bundleVetFlags
Expand All @@ -73,10 +71,6 @@ func init() {
bundleVetCmd.Flags().VarP(&bundleVetArgs.pkg, bundleVetArgs.pkg.Type(), bundleVetArgs.pkg.Shorthand(), bundleVetArgs.pkg.Description())
bundleVetCmd.Flags().StringSliceVarP(&bundleVetArgs.files, "file", "f", nil,
"The local path to bundle.cue files.")
bundleVetCmd.Flags().BoolVar(&bundleVetArgs.runtimeFromEnv, "runtime-from-env", false,
"Inject runtime values from the environment.")
bundleVetCmd.Flags().StringSliceVarP(&bundleVetArgs.runtimeFiles, "runtime", "r", nil,
"The local path to runtime.cue files.")
bundleVetCmd.Flags().BoolVar(&bundleVetArgs.printValue, "print-value", false,
"Print the computed value of the bundle.")
bundleCmd.AddCommand(bundleVetCmd)
Expand Down Expand Up @@ -114,15 +108,15 @@ func runBundleVetCmd(cmd *cobra.Command, args []string) error {

runtimeValues := make(map[string]string)

if bundleVetArgs.runtimeFromEnv {
if bundleArgs.runtimeFromEnv {
maps.Copy(runtimeValues, engine.GetEnv())
}

if len(bundleVetArgs.runtimeFiles) > 0 {
if len(bundleArgs.runtimeFiles) > 0 {
kctx, cancel := context.WithTimeout(cmd.Context(), rootArgs.timeout)
defer cancel()

rt, err := buildRuntime(bundleVetArgs.runtimeFiles)
rt, err := buildRuntime(bundleArgs.runtimeFiles)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/timoni/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func resetCmdArgs() {
listArgs = listFlags{}
pullModArgs = pullModFlags{}
pushModArgs = pushModFlags{}
bundleArgs = bundleFlags{}
bundleApplyArgs = bundleApplyFlags{}
bundleVetArgs = bundleVetFlags{}
bundleDelArgs = bundleDelFlags{}
Expand Down

0 comments on commit c917324

Please sign in to comment.