Skip to content

Commit

Permalink
integrate namespace config into commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Oct 28, 2022
1 parent 1255473 commit 83c22ec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ No local files are deleted.
fmt.Fprintf(cmd.OutOrStdout(), "error loading config at '%v'. %v\n", config.File(), err)
}

// Flag
// Flags
cmd.Flags().BoolP("confirm", "c", cfg.Confirm, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
cmd.Flags().StringP("namespace", "n", cfg.Namespace, "The namespace in which to delete. (Env: $FUNC_NAMESPACE)")
cmd.Flags().StringP("all", "a", "true", "Delete all resources created for a function, eg. Pipelines, Secrets, etc. (Env: $FUNC_ALL) (allowed values: \"true\", \"false\")")
setPathFlag(cmd)

Expand Down
9 changes: 9 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"gopkg.in/yaml.v2"

fn "knative.dev/func"
"knative.dev/func/config"
)

func NewInfoCmd(newClient ClientFactory) *cobra.Command {
Expand All @@ -35,7 +36,15 @@ the current directory or from the directory specified with --path.
PreRunE: bindEnv("output", "path"),
}

// Config
cfg, err := config.NewDefault()
if err != nil {
fmt.Fprintf(cmd.OutOrStdout(), "error loading config at '%v'. %v\n", config.File(), err)
}

// Flags
cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|xml|yaml|url) (Env: $FUNC_OUTPUT)")
cmd.Flags().StringP("namespace", "n", cfg.Namespace, "The namespace in which to look for the named function. (Env: $FUNC_NAMESPACE)")
setPathFlag(cmd)

if err := cmd.RegisterFlagCompletionFunc("output", CompleteOutputFormatList); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"gopkg.in/yaml.v2"

fn "knative.dev/func"
"knative.dev/func/config"
)

func NewListCmd(newClient ClientFactory) *cobra.Command {
Expand All @@ -38,7 +39,15 @@ Lists all deployed functions in a given namespace.
PreRunE: bindEnv("all-namespaces", "output"),
}

// Config
cfg, err := config.NewDefault()
if err != nil {
fmt.Fprintf(cmd.OutOrStdout(), "error loading config at '%v'. %v\n", config.File(), err)
}

// Flags
cmd.Flags().BoolP("all-namespaces", "A", false, "List functions in all namespaces. If set, the --namespace flag is ignored.")
cmd.Flags().StringP("namespace", "n", cfg.Namespace, "The namespace for which to list functions. (Env: $FUNC_NAMESPACE)")
cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|xml|yaml) (Env: $FUNC_OUTPUT)")

if err := cmd.RegisterFlagCompletionFunc("output", CompleteOutputFormatList); err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ func runRepositoryAdd(_ *cobra.Command, args []string, newClient ClientFactory)
// be created in XDG_CONFIG_HOME/func even if the repo path environment
// was set to some other location on disk.
client, done := newClient(ClientConfig{Verbose: cfg.Verbose})

defer done()

// Preconditions
Expand Down

0 comments on commit 83c22ec

Please sign in to comment.