Files
zot/pkg/cli/client/config_cmd_deprecated.go
Andrei Aaron c7ddbe2e36 feat(zli): add config list/show/get/set/reset and isolate deprecated syntax (#4037)
* feat(zli): add config list/show/get/set/reset and isolate deprecated syntax

Introduce first-class subcommands for listing profiles, showing a profile,
getting and setting keys, and resetting optional keys (alongside existing add/remove).
The parent command now resolves ~/.zot via zliUserConfigPath(),
documents that profile names must not clash with subcommand names,
and states that positional/--list/--reset usage is deprecated and will be removed soon.

Legacy behavior is delegated to config_cmd_deprecated.go with stderr warnings for old flags and positional get/set.
Examples and inline help point users at the new commands.
FormatNames/FormatListedVars comments reference config list/show.

Tests are split so config_cmd_test.go exercises the supported subcommands
while config_cmd_deprecated_test.go retains coverage for the deprecated
paths under renamed TestConfigCmdDeprecated* entries.

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

* test: stabilize retention check tests

See https://github.com/project-zot/zot/actions/runs/25361779632/job/74362802944?pr=4037

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
2026-05-08 20:19:26 +03:00

90 lines
2.1 KiB
Go

//go:build search
package client
import (
"fmt"
"io"
"github.com/spf13/cobra"
zerr "zotregistry.dev/zot/v2/errors"
)
// runLegacyConfig handles deprecated positional syntax and --list/--reset on the parent command.
// Prefer subcommands (list, show, get, set, reset); this file emits deprecation warnings to stderr.
func runLegacyConfig(cmd *cobra.Command, args []string, configPath string, isListing, isReset bool) error {
switch len(args) {
case noArgs:
if isListing { // zli config -l
warnLegacyDeprecatedInvocation(cmd.ErrOrStderr(), "`zli config --list`", "`zli config list`")
res, err := getConfigNames(configPath)
if err != nil {
return err
}
fmt.Fprint(cmd.OutOrStdout(), res)
return nil
}
return zerr.ErrInvalidArgs
case oneArg:
// zli config <name> -l
if isListing {
warnLegacyDeprecatedInvocation(cmd.ErrOrStderr(), "`zli config <name> --list`", "`zli config show <name>`")
res, err := getAllConfig(configPath, args[0])
if err != nil {
return err
}
fmt.Fprint(cmd.OutOrStdout(), res)
return nil
}
return zerr.ErrInvalidArgs
case twoArgs:
if isReset { // zli config <name> <key> --reset
warnLegacyDeprecatedInvocation(
cmd.ErrOrStderr(),
"`zli config <name> <key> --reset`",
"`zli config reset <name> <key>`",
)
return resetConfigValue(configPath, args[0], args[1])
}
warnLegacyDeprecatedInvocation(cmd.ErrOrStderr(), "`zli config <name> <key>`", "`zli config get <name> <key>`")
res, err := getConfigValue(configPath, args[0], args[1])
if err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), res)
case threeArgs:
warnLegacyDeprecatedInvocation(
cmd.ErrOrStderr(),
"`zli config <name> <key> <value>`",
"`zli config set <name> <key> <value>`",
)
if err := setConfigValue(configPath, args[0], args[1], args[2]); err != nil {
return err
}
default:
return zerr.ErrInvalidArgs
}
return nil
}
func warnLegacyDeprecatedInvocation(w io.Writer, invoked, replacement string) {
fmt.Fprintf(w, "Warning: deprecated invocation %s; use %s instead.\n", invoked, replacement)
}