Skip to content

Commit

Permalink
ensure flags take precedence over cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhatter committed Feb 13, 2024
1 parent c72145b commit 1ccdace
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 89 deletions.
13 changes: 8 additions & 5 deletions docs/fox.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ and release your KubeFox Apps.
### Options

```
-a, --app string path to directory containing KubeFox App
-h, --help help for fox
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-h, --help help for fox
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ fox build my-component --publish
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ See each sub-command's help for details on how to use the generated script.
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ fox completion bash
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_completion_fish.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ fox completion fish [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_completion_powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ fox completion powershell [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_completion_zsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ fox completion zsh [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ Use the config subcommand to help setup your local environment.
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_config_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ fox config setup [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_config_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ fox config show [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ fox deploy [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ fox docs [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ fox init [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ fox proxy 8080 --virtual-env my-env --app-deployment my-dep
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ fox publish [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ fox release v1.2.3 --virtual-env prod
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
11 changes: 7 additions & 4 deletions docs/fox_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ fox version [flags]
### Options inherited from parent commands

```
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
-v, --verbose enable verbose output
-a, --app string path to directory containing KubeFox App
-i, --info enable info output
-o, --output string output format, one of ["json", "yaml"] (default "yaml")
--registry-address string address of your container registry
--registry-token string access token for your container registry
--registry-username string username for your container registry
-v, --verbose enable verbose output
```

### SEE ALSO
Expand Down
12 changes: 10 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cli/oauth/device"
"github.com/xigxog/fox/internal/log"
"github.com/xigxog/fox/internal/utils"
kfutils "github.com/xigxog/kubefox/utils"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -87,7 +88,15 @@ type ContainerRegistry struct {
}

func (cfg *Config) IsRegistryLocal() bool {
return strings.HasPrefix(cfg.ContainerRegistry.Address, LocalRegistry)
return strings.HasPrefix(cfg.GetContainerRegistry().Address, LocalRegistry)
}

func (cfg *Config) GetContainerRegistry() ContainerRegistry {
return ContainerRegistry{
Address: kfutils.First(cfg.Flags.RegistryAddress, cfg.ContainerRegistry.Address),
Token: kfutils.First(cfg.Flags.RegistryToken, cfg.ContainerRegistry.Token),
Username: kfutils.First(cfg.Flags.RegistryUsername, cfg.ContainerRegistry.Username),
}
}

func (cfg *Config) Load() {
Expand Down Expand Up @@ -234,7 +243,6 @@ func (cfg *Config) setupRegistry() {
cfg.ContainerRegistry.Address = utils.InputPrompt("Enter the container registry endpoint you'd like to use", "", true)
cfg.ContainerRegistry.Username = utils.InputPrompt("Enter the container registry username (if required)", "", false)
cfg.ContainerRegistry.Token = utils.InputPrompt("Enter the container registry access token or password", "", true)
return
}

func (cfg *Config) setupGitHub() {
Expand Down
24 changes: 12 additions & 12 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import "time"

type Flags struct {
// persistent flags defined in root command
AppPath string
OutFormat string
AppPath string
OutFormat string
RegistryAddress string
RegistryToken string
RegistryUsername string

DryRun bool
Info bool
Verbose bool

// flags used by subcommands
AppDeployment string
Builder string
Kind string
Namespace string
Platform string
Version string
VirtEnv string
RegistryAddress string
RegistryUsername string
RegistryToken string
AppDeployment string
Builder string
Kind string
Namespace string
Platform string
Version string
VirtEnv string

CreateTag bool
ForceBuild bool
Expand Down
Loading

0 comments on commit 1ccdace

Please sign in to comment.