Skip to content

Commit

Permalink
Merge pull request #3638 from tstromberg/console
Browse files Browse the repository at this point in the history
Initial implementation of 'console' package for stylized & localized console output 😂
  • Loading branch information
tstromberg committed Feb 12, 2019
2 parents 50d69c0 + 0a5b64e commit ec5107e
Show file tree
Hide file tree
Showing 174 changed files with 118,192 additions and 2,050 deletions.
48 changes: 46 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@
[[constraint]]
name = "github.com/google/go-cmp"
version = "0.2.0"

[[constraint]]
name = "golang.org/x/text"
branch = "master"
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
)
Expand All @@ -42,12 +42,12 @@ var addCacheCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// Cache and load images into docker daemon
if err := machine.CacheAndLoadImages(args); err != nil {
fmt.Fprintf(os.Stderr, "Error caching and loading images: %v\n", err)
console.Fatal("Failed to cache and load images: %v", err)
os.Exit(1)
}
// Add images to config file
if err := cmdConfig.AddToConfigMap(constants.Cache, args); err != nil {
fmt.Fprintf(os.Stderr, "Error adding cached images to config file: %v\n", err)
console.Fatal("Failed to update config: %v", err)
os.Exit(1)
}
},
Expand All @@ -61,12 +61,12 @@ var deleteCacheCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// Delete images from config file
if err := cmdConfig.DeleteFromConfigMap(constants.Cache, args); err != nil {
fmt.Fprintf(os.Stderr, "Error deleting images from config file: %v\n", err)
console.Fatal("Failed to delete images from config: %v", err)
os.Exit(1)
}
// Delete images from cache/images directory
if err := machine.DeleteFromImageCacheDir(args); err != nil {
fmt.Fprintf(os.Stderr, "Error deleting images: %v\n", err)
console.Fatal("Failed to delete images: %v", err)
os.Exit(1)
}
},
Expand Down
11 changes: 5 additions & 6 deletions cmd/minikube/cmd/cache_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"text/template"

"github.com/spf13/cobra"
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
)

Expand All @@ -38,14 +38,13 @@ var listCacheCmd = &cobra.Command{
Short: "List all available images from the local cache.",
Long: "List all available images from the local cache.",
Run: func(cmd *cobra.Command, args []string) {
// list images from config file
images, err := cmdConfig.ListConfigMap(constants.Cache)
if err != nil {
fmt.Fprintf(os.Stderr, "Error listing image entries from config: %v\n", err)
console.Fatal("Failed to get image map: %v", err)
os.Exit(1)
}
if err := cacheList(images); err != nil {
fmt.Fprintf(os.Stderr, "Error listing images: %v\n", err)
console.Fatal("Failed to list cached images: %v", err)
os.Exit(1)
}
},
Expand All @@ -62,13 +61,13 @@ func cacheList(images []string) error {
for _, image := range images {
tmpl, err := template.New("list").Parse(cacheListFormat)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating list template: %v\n", err)
console.Fatal("Unable to parse template: %v", err)
os.Exit(1)
}
listTmplt := CacheListTemplate{image}
err = tmpl.Execute(os.Stdout, listTmplt)
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing list template: %v\n", err)
console.Fatal("Unable to process template: %v", err)
os.Exit(1)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package cmd

import (
"bytes"
"fmt"
"io"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
cmdutil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/console"
)

const longDescription = `
Expand Down Expand Up @@ -70,11 +70,11 @@ var completionCmd = &cobra.Command{
Long: longDescription,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Usage: minikube completion SHELL")
console.ErrStyle("usage", "Usage: minikube completion SHELL")
os.Exit(1)
}
if args[0] != "bash" && args[0] != "zsh" {
fmt.Println("Only bash and zsh are supported for minikube completion")
console.Fatal("Sorry, completion support is not yet implemented for %q", args[0])
os.Exit(1)
} else if args[0] == "bash" {
err := GenerateBashCompletion(os.Stdout, cmd.Parent())
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ limitations under the License.
package config

import (
"fmt"
"os"
"sort"
"text/template"

"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
)

Expand All @@ -41,12 +41,12 @@ var addonsListCmd = &cobra.Command{
Long: "Lists all available minikube addons as well as their current statuses (enabled/disabled)",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
fmt.Fprintln(os.Stderr, "usage: minikube addons list")
console.ErrStyle("usage", "usage: minikube addons list")
os.Exit(1)
}
err := addonList()
if err != nil {
fmt.Fprintln(os.Stderr, err)
console.Fatal("addon list failed: %v", err)
os.Exit(1)
}
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/config_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ limitations under the License.
package config

import (
"fmt"
"os"
"text/template"

"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/constants"
)

Expand All @@ -41,7 +41,7 @@ var configViewCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := configView()
if err != nil {
fmt.Fprintln(os.Stderr, err)
console.Fatal("config view failed: %v", err)
os.Exit(1)
}
},
Expand Down
18 changes: 8 additions & 10 deletions cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package config

import (
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/service"
)

Expand All @@ -31,7 +31,7 @@ var addonsConfigureCmd = &cobra.Command{
Long: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "usage: minikube addons configure ADDON_NAME")
console.ErrStyle("usage", "usage: minikube addons configure ADDON_NAME")
os.Exit(1)
}

Expand Down Expand Up @@ -78,7 +78,7 @@ var addonsConfigureCmd = &cobra.Command{
dat, err := ioutil.ReadFile(gcrPath)

if err != nil {
fmt.Println("Could not read file for application_default_credentials.json")
console.Failure("Error reading %s: %v", gcrPath, err)
} else {
gcrApplicationDefaultCredentials = string(dat)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
fmt.Println("ERROR creating `registry-creds-ecr` secret")
console.Failure("ERROR creating `registry-creds-ecr` secret: %v", err)
}

// Create GCR Secret
Expand All @@ -128,7 +128,7 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
fmt.Println("ERROR creating `registry-creds-gcr` secret")
console.Failure("ERROR creating `registry-creds-gcr` secret: %v", err)
}

// Create Docker Secret
Expand All @@ -147,16 +147,14 @@ var addonsConfigureCmd = &cobra.Command{
})

if err != nil {
fmt.Println("ERROR creating `registry-creds-dpr` secret")
console.Warning("ERROR creating `registry-creds-dpr` secret")
}

break
default:
fmt.Fprintln(os.Stdout, fmt.Sprintf("%s has no available configuration options", addon))
console.Failure("%s has no available configuration options", addon)
return
}

fmt.Fprintln(os.Stdout, fmt.Sprintf("%s was successfully configured", addon))
console.Success("%s was successfully configured", addon)
},
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/config/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
package config

import (
"fmt"
"os"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/console"
)

var addonsDisableCmd = &cobra.Command{
Expand All @@ -29,17 +29,17 @@ var addonsDisableCmd = &cobra.Command{
Long: "Disables the addon w/ADDON_NAME within minikube (example: minikube addons disable dashboard). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "usage: minikube addons disable ADDON_NAME")
console.ErrStyle("usage", "usage: minikube addons disable ADDON_NAME")
os.Exit(1)
}

addon := args[0]
err := Set(addon, "false")
if err != nil {
fmt.Fprintln(os.Stdout, err)
console.Fatal("disable failed: %v", err)
os.Exit(1)
}
fmt.Fprintln(os.Stdout, fmt.Sprintf("%s was successfully disabled", addon))
console.Success("%s was successfully disabled", addon)
},
}

Expand Down
Loading

0 comments on commit ec5107e

Please sign in to comment.