mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
cli: move client-only code out of the server flow
earlier, some of the client exclusive code was being run on zot server instance too. cli: fix the bug: spinner is not stopped with -o
This commit is contained in:
+17
-4
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewConfigCommand(configPath string) *cobra.Command {
|
||||
func NewConfigCommand() *cobra.Command {
|
||||
var isListing bool
|
||||
|
||||
var isReset bool
|
||||
@@ -28,6 +29,12 @@ func NewConfigCommand(configPath string) *cobra.Command {
|
||||
Long: `Configure default parameters for CLI`,
|
||||
Args: cobra.ArbitraryArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configPath := path.Join(home + "/.zot")
|
||||
switch len(args) {
|
||||
case noArgs:
|
||||
if isListing { // zot config -l
|
||||
@@ -83,20 +90,26 @@ func NewConfigCommand(configPath string) *cobra.Command {
|
||||
configCmd.Flags().BoolVarP(&isListing, "list", "l", false, "List configurations")
|
||||
configCmd.Flags().BoolVar(&isReset, "reset", false, "Reset a variable value")
|
||||
configCmd.SetUsageTemplate(configCmd.UsageTemplate() + supportedOptions)
|
||||
configCmd.AddCommand(NewConfigAddCommand(configPath))
|
||||
configCmd.AddCommand(NewConfigAddCommand())
|
||||
|
||||
return configCmd
|
||||
}
|
||||
|
||||
func NewConfigAddCommand(configPath string) *cobra.Command {
|
||||
func NewConfigAddCommand() *cobra.Command {
|
||||
var configAddCmd = &cobra.Command{
|
||||
Use: "add <config-name> <url>",
|
||||
Short: "Add configuration for a zot URL",
|
||||
Long: `Configure CLI for interaction with a zot server`,
|
||||
Args: cobra.ExactArgs(twoArgs),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configPath := path.Join(home + "/.zot")
|
||||
// zot config add <config-name> <url>
|
||||
err := addConfig(configPath, args[0], args[1])
|
||||
err = addConfig(configPath, args[0], args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user