Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/cli/cmd/config_reset.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2023-2025 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,9 @@ func newConfigResetCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "reset",
Short: "Reset the CLI configuration",
Annotations: map[string]string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this affect all the config commands? Otherwise if it's failing you'll not be able to set it again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does affect all of them, but I've excluded config plugin because it uses some of the fields that actionopts contain. Subcommands don't inherit annotations from parents so it has to be added to each command.

skipActionOptsInit: trueString,
},
Run: func(cmd *cobra.Command, args []string) {
configFile := viper.ConfigFileUsed()
err := os.Remove(configFile)
Expand Down
5 changes: 4 additions & 1 deletion app/cli/cmd/config_save.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2023-2025 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,9 @@ func newConfigSaveCmd() *cobra.Command {
Use: "save",
Short: "Persist the current settings to the config file",
Example: "chainloop config save --control-plane localhost:1234 --artifact-cas localhost:1235",
Annotations: map[string]string{
skipActionOptsInit: trueString,
},
RunE: func(cmd *cobra.Command, args []string) error {
return viper.WriteConfig()
},
Expand Down
5 changes: 4 additions & 1 deletion app/cli/cmd/config_view.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2023-2025 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,9 @@ func newConfigViewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "view",
Short: "View the current CLI configuration",
Annotations: map[string]string{
skipActionOptsInit: trueString,
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Config file: %s\n", viper.ConfigFileUsed())

Expand Down
15 changes: 13 additions & 2 deletions app/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const (
useAPIToken = "withAPITokenAuth"
// Ask for confirmation when user token is used and API token is preferred
confirmWhenUserToken = "confirmWhenUserToken"
appName = "chainloop"
// Skip ActionOpts initialization for commands that operate locally
skipActionOptsInit = "skipActionOptsInit"
appName = "chainloop"
//nolint:gosec
tokenEnvVarName = "CHAINLOOP_TOKEN"
// Follow the convention stated on https://consoledonottrack.com/
Expand Down Expand Up @@ -102,6 +104,12 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {

logger.Debug().Str("path", viper.ConfigFileUsed()).Msg("using config file")

// Commands annotated with skipActionOptsInit don't need ActionOpts initialization
// These are local-only commands that don't interact with the control plane
if cmd.Annotations[skipActionOptsInit] == trueString {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming this will not fail if the annotation is not set correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

return nil
}

if apiInsecure() {
logger.Warn().Msg("API contacted in insecure mode")
}
Expand Down Expand Up @@ -203,7 +211,10 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
return nil
},
PersistentPostRunE: func(_ *cobra.Command, _ []string) error {
return cleanup(ActionOpts.CPConnection)
if ActionOpts != nil {
return cleanup(ActionOpts.CPConnection)
}
return nil
},
}

Expand Down
Loading