File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed
Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 11//
2- // Copyright 2023 The Chainloop Authors.
2+ // Copyright 2023-2025 The Chainloop Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -26,6 +26,9 @@ func newConfigResetCmd() *cobra.Command {
2626 cmd := & cobra.Command {
2727 Use : "reset" ,
2828 Short : "Reset the CLI configuration" ,
29+ Annotations : map [string ]string {
30+ skipActionOptsInit : trueString ,
31+ },
2932 Run : func (cmd * cobra.Command , args []string ) {
3033 configFile := viper .ConfigFileUsed ()
3134 err := os .Remove (configFile )
Original file line number Diff line number Diff line change 11//
2- // Copyright 2023 The Chainloop Authors.
2+ // Copyright 2023-2025 The Chainloop Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -25,6 +25,9 @@ func newConfigSaveCmd() *cobra.Command {
2525 Use : "save" ,
2626 Short : "Persist the current settings to the config file" ,
2727 Example : "chainloop config save --control-plane localhost:1234 --artifact-cas localhost:1235" ,
28+ Annotations : map [string ]string {
29+ skipActionOptsInit : trueString ,
30+ },
2831 RunE : func (cmd * cobra.Command , args []string ) error {
2932 return viper .WriteConfig ()
3033 },
Original file line number Diff line number Diff line change 11//
2- // Copyright 2023 The Chainloop Authors.
2+ // Copyright 2023-2025 The Chainloop Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -26,6 +26,9 @@ func newConfigViewCmd() *cobra.Command {
2626 cmd := & cobra.Command {
2727 Use : "view" ,
2828 Short : "View the current CLI configuration" ,
29+ Annotations : map [string ]string {
30+ skipActionOptsInit : trueString ,
31+ },
2932 Run : func (cmd * cobra.Command , args []string ) {
3033 fmt .Printf ("Config file: %s\n " , viper .ConfigFileUsed ())
3134
Original file line number Diff line number Diff line change @@ -58,7 +58,9 @@ const (
5858 useAPIToken = "withAPITokenAuth"
5959 // Ask for confirmation when user token is used and API token is preferred
6060 confirmWhenUserToken = "confirmWhenUserToken"
61- appName = "chainloop"
61+ // Skip ActionOpts initialization for commands that operate locally
62+ skipActionOptsInit = "skipActionOptsInit"
63+ appName = "chainloop"
6264 //nolint:gosec
6365 tokenEnvVarName = "CHAINLOOP_TOKEN"
6466 // Follow the convention stated on https://consoledonottrack.com/
@@ -102,6 +104,12 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
102104
103105 logger .Debug ().Str ("path" , viper .ConfigFileUsed ()).Msg ("using config file" )
104106
107+ // Commands annotated with skipActionOptsInit don't need ActionOpts initialization
108+ // These are local-only commands that don't interact with the control plane
109+ if cmd .Annotations [skipActionOptsInit ] == trueString {
110+ return nil
111+ }
112+
105113 if apiInsecure () {
106114 logger .Warn ().Msg ("API contacted in insecure mode" )
107115 }
@@ -203,7 +211,10 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
203211 return nil
204212 },
205213 PersistentPostRunE : func (_ * cobra.Command , _ []string ) error {
206- return cleanup (ActionOpts .CPConnection )
214+ if ActionOpts != nil {
215+ return cleanup (ActionOpts .CPConnection )
216+ }
217+ return nil
207218 },
208219 }
209220
You can’t perform that action at this time.
0 commit comments