all.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package commands
  2. import (
  3. "github.com/porter-dev/porter/cli/cmd/config"
  4. "github.com/spf13/cobra"
  5. )
  6. // func rootFunc(cmd *cobra.Command, args []string) error {
  7. // ctx := cmd.Context()
  8. // flagsConfig := parseRootConfigFlags(cmd)
  9. // profile, err := cmd.Flags().GetString("profile")
  10. // if err != nil {
  11. // return fmt.Errorf("error getting profile flag: %w", err)
  12. // }
  13. // cliConf, currentProfile, err := config.InitAndLoadConfig(ctx, profile, flagsConfig)
  14. // if err != nil {
  15. // fmt.Println("unwrapped", errors.Unwrap(err))
  16. // return fmt.Errorf("error whilst initialising config: %w", err)
  17. // }
  18. // cmd.PersistentFlags().AddFlagSet(utils.DefaultFlagSet)
  19. // cmd.AddCommand(registerCommand_App(cliConf, currentProfile))
  20. // cmd.AddCommand(registerCommand_Apply(cliConf, currentProfile))
  21. // cmd.AddCommand(registerCommand_Auth(cliConf, currentProfile))
  22. // cmd.AddCommand(registerCommand_Cluster(cliConf, currentProfile))
  23. // cmd.AddCommand(registerCommand_Config(cliConf, currentProfile))
  24. // cmd.AddCommand(registerCommand_Connect(cliConf, currentProfile))
  25. // cmd.AddCommand(registerCommand_Create(cliConf, currentProfile))
  26. // cmd.AddCommand(registerCommand_Delete(cliConf, currentProfile))
  27. // cmd.AddCommand(registerCommand_Deploy(cliConf, currentProfile))
  28. // cmd.AddCommand(registerCommand_Docker(cliConf, currentProfile))
  29. // cmd.AddCommand(registerCommand_Get(cliConf, currentProfile))
  30. // cmd.AddCommand(registerCommand_Helm(cliConf, currentProfile))
  31. // cmd.AddCommand(registerCommand_Job(cliConf, currentProfile))
  32. // cmd.AddCommand(registerCommand_Kubectl(cliConf, currentProfile))
  33. // cmd.AddCommand(registerCommand_List(cliConf, currentProfile))
  34. // cmd.AddCommand(registerCommand_Logs(cliConf, currentProfile))
  35. // cmd.AddCommand(registerCommand_Open(cliConf, currentProfile))
  36. // cmd.AddCommand(registerCommand_PortForward(cliConf, currentProfile))
  37. // cmd.AddCommand(registerCommand_Project(cliConf, currentProfile))
  38. // cmd.AddCommand(registerCommand_Registry(cliConf, currentProfile))
  39. // cmd.AddCommand(registerCommand_Run(cliConf, currentProfile))
  40. // cmd.AddCommand(registerCommand_Server(cliConf, currentProfile))
  41. // cmd.AddCommand(registerCommand_Stack(cliConf, currentProfile))
  42. // cmd.AddCommand(registerCommand_Update(cliConf, currentProfile))
  43. // cmd.AddCommand(registerCommand_Version(cliConf, currentProfile))
  44. // return nil
  45. // }
  46. // parseRootConfigFlags grabs the runtime value of registered root level persisted flags.
  47. func parseRootConfigFlags(cmd *cobra.Command) config.CLIConfig {
  48. type flag struct {
  49. // stringName is the name of the flag which is a string
  50. stringName string
  51. // stringConfigTarget is the pointer to the string in the config struct
  52. stringConfigTarget *string
  53. // uintName is the name of the flag which is a uint
  54. uintName string
  55. // uintConfigTarget is the pointer to the uint in the config struct
  56. uintConfigTarget *uint
  57. }
  58. var profile string
  59. var config config.CLIConfig
  60. flagsToOverride := []flag{
  61. {
  62. stringName: "driver",
  63. stringConfigTarget: &config.Driver,
  64. },
  65. {
  66. stringName: "host",
  67. stringConfigTarget: &config.Host,
  68. },
  69. {
  70. stringName: "token",
  71. stringConfigTarget: &config.Token,
  72. },
  73. {
  74. stringName: "kubeconfig",
  75. stringConfigTarget: &config.Kubeconfig,
  76. },
  77. {
  78. stringName: "profile",
  79. stringConfigTarget: &profile,
  80. },
  81. {
  82. uintName: "project",
  83. uintConfigTarget: &config.Project,
  84. },
  85. {
  86. uintName: "cluster",
  87. uintConfigTarget: &config.Cluster,
  88. },
  89. {
  90. uintName: "registry",
  91. uintConfigTarget: &config.Registry,
  92. },
  93. {
  94. uintName: "helm_repo",
  95. uintConfigTarget: &config.HelmRepo,
  96. },
  97. }
  98. for _, fl := range flagsToOverride {
  99. if fl.stringName != "" {
  100. st, _ := cmd.Flags().GetString(fl.stringName)
  101. if st != "" {
  102. *fl.stringConfigTarget = st
  103. }
  104. }
  105. if fl.uintName != "" {
  106. ui, _ := cmd.Flags().GetUint(fl.uintName)
  107. if ui != 0 {
  108. *fl.uintConfigTarget = ui
  109. }
  110. }
  111. }
  112. return config
  113. }