2
0

app_image.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package flags
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. const (
  7. // App_ImageTag is the key for the image tag flag
  8. App_ImageTag = "tag"
  9. // App_ImageRepository is the key for the image repository flag
  10. App_ImageRepository = "image-repository"
  11. )
  12. // UseAppImageFlags adds image flags to the given command
  13. func UseAppImageFlags(cmd *cobra.Command) {
  14. cmd.PersistentFlags().String(
  15. App_ImageTag,
  16. "",
  17. "set the image tag used for the application (overrides field in yaml)",
  18. )
  19. cmd.PersistentFlags().String(
  20. App_ImageRepository,
  21. "",
  22. "set the image repository to use for the app",
  23. )
  24. }
  25. type imageValues struct {
  26. Tag string
  27. Repository string
  28. }
  29. // AppImageValuesFromCmd retrieves image values from command flags
  30. func AppImageValuesFromCmd(cmd *cobra.Command) (imageValues, error) {
  31. var values imageValues
  32. tag, err := cmd.Flags().GetString(App_ImageTag)
  33. if err != nil {
  34. return values, fmt.Errorf("error getting tag: %w", err)
  35. }
  36. repo, err := cmd.Flags().GetString(App_ImageRepository)
  37. if err != nil {
  38. return values, fmt.Errorf("error getting repository: %w", err)
  39. }
  40. values = imageValues{
  41. Tag: tag,
  42. Repository: repo,
  43. }
  44. return values, nil
  45. }