| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package flags
- import (
- "fmt"
- "github.com/spf13/cobra"
- )
- const (
- // App_BuildMethod is the key for the build method flag
- App_BuildMethod = "build-method"
- // App_Dockerfile is the key for the dockerfile flag
- App_Dockerfile = "dockerfile"
- // App_Builder is the key for the builder flag
- App_Builder = "builder"
- // App_Buildpacks is the key for the buildpacks flag
- App_Buildpacks = "attach-buildpacks"
- // App_BuildContext is the key for the build context flag
- App_BuildContext = "build-context"
- // App_NoBuild is the key for the no build flag
- App_NoBuild = "no-build"
- // App_NoPull is the key for the no pull flag
- App_NoPull = "no-pull"
- )
- // UseAppBuildFlags adds build flags to the given command
- func UseAppBuildFlags(cmd *cobra.Command) {
- cmd.PersistentFlags().String(
- App_BuildMethod,
- "",
- "set the build method for the app on apply, either 'docker' or 'pack'",
- )
- cmd.PersistentFlags().String(
- App_Dockerfile,
- "",
- "set the path to the Dockerfile when build method is 'docker'",
- )
- cmd.PersistentFlags().String(
- App_Builder,
- "",
- "set the builder to use when build method is 'pack'",
- )
- cmd.PersistentFlags().StringSlice(
- App_Buildpacks,
- nil,
- "attach buildpacks to use when build method is 'pack'",
- )
- cmd.PersistentFlags().String(
- App_BuildContext,
- "",
- "set the build context for the app",
- )
- }
- type buildValues struct {
- BuildMethod string
- Dockerfile string
- Builder string
- Buildpacks []string
- BuildContext string
- }
- // AppBuildValuesFromCmd retrieves build values from command flags
- func AppBuildValuesFromCmd(cmd *cobra.Command) (buildValues, error) {
- var values buildValues
- buildMethod, err := cmd.Flags().GetString(App_BuildMethod)
- if err != nil {
- return values, fmt.Errorf("error getting build method: %s", err)
- }
- dockerfile, err := cmd.Flags().GetString(App_Dockerfile)
- if err != nil {
- return values, fmt.Errorf("error getting dockerfile: %s", err)
- }
- builder, err := cmd.Flags().GetString(App_Builder)
- if err != nil {
- return values, fmt.Errorf("error getting builder: %s", err)
- }
- buildpacks, err := cmd.Flags().GetStringSlice(App_Buildpacks)
- if err != nil {
- return values, fmt.Errorf("error getting buildpacks: %s", err)
- }
- buildContext, err := cmd.Flags().GetString(App_BuildContext)
- if err != nil {
- return values, fmt.Errorf("error getting build context: %s", err)
- }
- values = buildValues{
- BuildMethod: buildMethod,
- Dockerfile: dockerfile,
- Builder: builder,
- Buildpacks: buildpacks,
- BuildContext: buildContext,
- }
- return values, nil
- }
|