Skip to content

Commit

Permalink
cli: make all prints use log module
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Jutteau <[email protected]>
  • Loading branch information
jerome-jutteau authored and outscale-mdr committed Mar 18, 2022
1 parent c8a7d9d commit 70427f3
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 156 deletions.
2 changes: 1 addition & 1 deletion cmd/frieza/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func cliRoot() cli.App {
func cliVersion() cli.Command {
return cli.NewCommand("version", "show version").
WithAction(func(args []string, options map[string]string) int {
fmt.Println(FullVersion())
log.Println(FullVersion())
return 0
})
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/frieza/cli_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"

. "github.com/outscale-dev/frieza/internal/common"
Expand Down Expand Up @@ -58,7 +57,7 @@ func cliConfigRm() cli.Command {
}

func configDescribe() {
fmt.Println("snapshot_folder_path: specify a folder path where snapshots are located")
log.Println("snapshot_folder_path: specify a folder path where snapshots are located")
}

func configLs(customConfigPath string) {
Expand All @@ -70,11 +69,11 @@ func configLs(customConfigPath string) {
if err != nil {
log.Fatalf("Cannot load configuration: %s", err.Error())
}
fmt.Println("version:", config.Version)
log.Println("version:", config.Version)
if len(config.SnapshotFolderPath) == 0 {
fmt.Println("snapshot_folder_path: (unset)")
log.Println("snapshot_folder_path: (unset)")
} else {
fmt.Println("snapshot_folder_path:", config.SnapshotFolderPath)
log.Println("snapshot_folder_path:", config.SnapshotFolderPath)
}
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/frieza/cli_profile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"

. "github.com/outscale-dev/frieza/internal/common"
Expand Down Expand Up @@ -99,7 +98,7 @@ func profileLs(customConfigPath string) {
log.Fatalf("Cannot load configuration: %s", err.Error())
}
for _, profile := range config.Profiles {
fmt.Println(profile.Name)
log.Println(profile.Name)
}
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/frieza/cli_provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/teris-io/cli"
)
Expand All @@ -17,7 +17,7 @@ func cliProviderLs() cli.Command {
WithShortcut("ls").
WithAction(func(args []string, options map[string]string) int {
for providerName := range providersTypes {
fmt.Printf("%s\n", providerName)
log.Printf("%s\n", providerName)
}
return 0
})
Expand All @@ -30,7 +30,7 @@ func cliProviderDescribe() cli.Command {
WithAction(func(args []string, options map[string]string) int {
providerName := args[0]
for _, providerType := range providersTypes[providerName] {
fmt.Printf("%s\n", providerType)
log.Printf("%s\n", providerType)
}
return 0
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/frieza/cli_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func snapshotLs(customConfigPath string) {
}
snapshotName := strings.TrimSuffix(file.Name(), ".json")
if snapshot, err := SnapshotLoad(snapshotName, config); err == nil {
fmt.Println(snapshot.Name)
log.Println(snapshot.Name)
}
}
}
Expand All @@ -174,7 +174,7 @@ func snapshotDescribe(customConfigPath string, snapshotName *string) {
if err != nil {
log.Fatalf("Cannot load snapshot %s: %s", *snapshotName, err.Error())
}
fmt.Print(snapshot)
log.Print(snapshot)
}

func snapshotRm(customConfigPath string, snapshotName *string) {
Expand Down
15 changes: 7 additions & 8 deletions cmd/frieza/destroyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"strings"
Expand Down Expand Up @@ -58,16 +57,16 @@ func (destroyer *Destroyer) print_human() {
totalObjectCount := 0
for i := 0; i < count; i++ {
target := destroyer.Targets[i]
fmt.Printf("Objects to delete in profile %s (%s):\n", target.profile.Name, (*target.provider).Name())
log.Printf("Objects to delete in profile %s (%s):\n", target.profile.Name, (*target.provider).Name())
objectsCount := ObjectsCount(target.Objects)
if objectsCount == 0 {
fmt.Println("* no object *")
log.Println("* no object *")
}
totalObjectCount += objectsCount
fmt.Print(ObjectsPrint(target.provider, target.Objects))
log.Print(ObjectsPrint(target.provider, target.Objects))
}
if totalObjectCount == 0 {
fmt.Println("\nNothing to delete")
log.Println("\nNothing to delete")
}
}

Expand Down Expand Up @@ -126,9 +125,9 @@ func confirmAction(message *string, autoApprove bool) bool {
if autoApprove {
return true
}
fmt.Printf("\n%s\n", *message)
fmt.Printf(" There is no undo. Only 'yes' will be accepted to confirm.\n\n")
fmt.Printf(" Enter a value: ")
log.Printf("\n%s\n", *message)
log.Printf(" There is no undo. Only 'yes' will be accepted to confirm.\n\n")
log.Printf(" Enter a value: ")
reader := bufio.NewReader(os.Stdin)
response, _ := reader.ReadString('\n')
response = strings.Replace(response, "\n", "", -1)
Expand Down
Loading

0 comments on commit 70427f3

Please sign in to comment.