diff --git a/command/container/list.go b/command/container/list.go index 60c2462986..5104e9b6c0 100644 --- a/command/container/list.go +++ b/command/container/list.go @@ -10,7 +10,7 @@ import ( "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/formatter" "github.com/docker/docker/opts" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" "github.com/spf13/cobra" ) diff --git a/command/formatter/formatter.go b/command/formatter/formatter.go index e859a1ca26..4345f7c3bc 100644 --- a/command/formatter/formatter.go +++ b/command/formatter/formatter.go @@ -8,7 +8,7 @@ import ( "text/tabwriter" "text/template" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" ) // Format keys used to specify certain kinds of output formats diff --git a/command/inspect/inspector.go b/command/inspect/inspector.go index 1d81643fb1..1e53671f84 100644 --- a/command/inspect/inspector.go +++ b/command/inspect/inspector.go @@ -9,7 +9,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/cli" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" ) // Inspector defines an interface to implement to process elements diff --git a/command/inspect/inspector_test.go b/command/inspect/inspector_test.go index 1ce1593ab7..9085230ac5 100644 --- a/command/inspect/inspector_test.go +++ b/command/inspect/inspector_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" ) type testElement struct { diff --git a/command/system/events.go b/command/system/events.go index 087523051a..441ef91d33 100644 --- a/command/system/events.go +++ b/command/system/events.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/cli/command" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" "github.com/spf13/cobra" ) diff --git a/command/system/info.go b/command/system/info.go index 973ee18241..ec1cf47de2 100644 --- a/command/system/info.go +++ b/command/system/info.go @@ -12,9 +12,9 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" + "github.com/docker/docker/cli/debug" "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/utils" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" "github.com/docker/go-units" "github.com/spf13/cobra" ) @@ -206,7 +206,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Name: %s\n", info.Name) ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID) fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir) - fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", utils.IsDebugEnabled()) + fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", debug.IsEnabled()) fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug) if info.Debug { diff --git a/command/system/version.go b/command/system/version.go index ded4f4d118..569da21886 100644 --- a/command/system/version.go +++ b/command/system/version.go @@ -11,7 +11,7 @@ import ( "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/dockerversion" - "github.com/docker/docker/utils/templates" + "github.com/docker/docker/pkg/templates" "github.com/spf13/cobra" ) diff --git a/debug/debug.go b/debug/debug.go new file mode 100644 index 0000000000..51dfab2a97 --- /dev/null +++ b/debug/debug.go @@ -0,0 +1,26 @@ +package debug + +import ( + "os" + + "github.com/Sirupsen/logrus" +) + +// Enable sets the DEBUG env var to true +// and makes the logger to log at debug level. +func Enable() { + os.Setenv("DEBUG", "1") + logrus.SetLevel(logrus.DebugLevel) +} + +// Disable sets the DEBUG env var to false +// and makes the logger to log at info level. +func Disable() { + os.Setenv("DEBUG", "") + logrus.SetLevel(logrus.InfoLevel) +} + +// IsEnabled checks whether the debug flag is set or not. +func IsEnabled() bool { + return os.Getenv("DEBUG") != "" +} diff --git a/debug/debug_test.go b/debug/debug_test.go new file mode 100644 index 0000000000..ad8412a944 --- /dev/null +++ b/debug/debug_test.go @@ -0,0 +1,43 @@ +package debug + +import ( + "os" + "testing" + + "github.com/Sirupsen/logrus" +) + +func TestEnable(t *testing.T) { + defer func() { + os.Setenv("DEBUG", "") + logrus.SetLevel(logrus.InfoLevel) + }() + Enable() + if os.Getenv("DEBUG") != "1" { + t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG")) + } + if logrus.GetLevel() != logrus.DebugLevel { + t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel()) + } +} + +func TestDisable(t *testing.T) { + Disable() + if os.Getenv("DEBUG") != "" { + t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG")) + } + if logrus.GetLevel() != logrus.InfoLevel { + t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel()) + } +} + +func TestEnabled(t *testing.T) { + Enable() + if !IsEnabled() { + t.Fatal("expected debug enabled, got false") + } + Disable() + if IsEnabled() { + t.Fatal("expected debug disabled, got true") + } +}