Skip to content

Commit

Permalink
cli: add command family: config
Browse files Browse the repository at this point in the history
Only "config list" is supported for now

Signed-off-by: Jérôme Jutteau <[email protected]>
  • Loading branch information
jerome-jutteau committed Mar 16, 2022
1 parent c042b67 commit 48f78b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/frieza/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func cliRoot() cli.App {
WithCommand(cliClean()).
WithCommand(cliNuke()).
WithCommand(cliProvider()).
WithCommand(cliConfig()).
WithCommand(cliVersion())
}

Expand Down
42 changes: 42 additions & 0 deletions cmd/frieza/cli_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"log"

. "github.com/outscale-dev/frieza/internal/common"
"github.com/teris-io/cli"
)

func cliConfig() cli.Command {
return cli.NewCommand("config", "configure frieza options").
WithCommand(cliConfigLs())
}

func cliConfigLs() cli.Command {
return cli.NewCommand("list", "list configuration options").
WithOption(cliConfigPath()).
WithShortcut("ls").
WithAction(func(args []string, options map[string]string) int {
configLs(options["config"])
return 0
})
}

func configLs(customConfigPath string) {
var configPath *string
if len(customConfigPath) > 0 {
configPath = &customConfigPath
}
config, err := ConfigLoad(configPath)
if err != nil {
log.Fatalf("Cannot load configuration: %s", err.Error())
}
fmt.Println("configuration path:", *configPath)
fmt.Println("version:", config.Version)
if len(config.SnapshotFolderPath) == 0 {
fmt.Println("snapshot_folder_path: (unset)")
} else {
fmt.Println("snapshot_folder_path:", config.SnapshotFolderPath)
}
}

0 comments on commit 48f78b3

Please sign in to comment.