From 9d25a0e5d51cec81292a4a1529dcf8ee16e893a4 Mon Sep 17 00:00:00 2001 From: zelahi Date: Mon, 22 Jul 2019 15:38:33 -0700 Subject: [PATCH] Added prune and hello world commands --- commands/hello.go | 27 +++++++++++++++++++++++++ commands/prune.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ commands/root.go | 2 ++ 3 files changed, 80 insertions(+) create mode 100644 commands/hello.go create mode 100644 commands/prune.go diff --git a/commands/hello.go b/commands/hello.go new file mode 100644 index 00000000..d6cdd46d --- /dev/null +++ b/commands/hello.go @@ -0,0 +1,27 @@ +package commands + +import ( + "fmt" + + "github.com/docker/buildx/version" + "github.com/docker/cli/cli" + "github.com/docker/cli/cli/command" + "github.com/spf13/cobra" +) + +func runHelloWorld(dockerCli command.Cli) error { + fmt.Println("hello world") + return nil +} + +func helloCmd(dockerCli command.Cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "hello", + Short: "I think this is how cmds are added ", + Args: cli.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + return runHelloWorld(dockerCli) + }, + } + return cmd +} diff --git a/commands/prune.go b/commands/prune.go new file mode 100644 index 00000000..5f42bca2 --- /dev/null +++ b/commands/prune.go @@ -0,0 +1,51 @@ +// Command used for prune +package commands + +import "fmt" +import "github.com/docker/cli/cli/command" + +func pruneCmd(dockerCli command.Cli) *cobra.Command { + fmt.Println("ASDF - pruneCmd") + + cmd := &cobra.Command{ + Use: "docker buildx prune" + Short: "Cleans up the build cache" + Args: cli.NoArgs + RunE: func(cmd *cobra.Command, args []string) error { + spaceReclaimed, output, err := runPrune(dockerCli, options) + if err != nil { + return err + } + + if output != "" { + fmt.Fprintln(dockerCli.Out(), output) + } + fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) + return nil + + }, + Annotations: map[string]string{"version": "1.00"}, + } + + // ToDo: Uncomment and test this out once we get the base feature working + //flags := cmd.Flags() + //flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") + //flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=')") + + const ( + normalWarning = `WARNING! This will remove all dangling build cache. Are you sure you want to continue?` + allCacheWarning = `WARNING! This will remove all build cache. Are you sure you want to continue?` + ) + + return cmd + +} + + +func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) { + fmt.Println("ASDF runPrune - Hello world") + + // ToDo: Implement this function + + return 0, "Not implemented", nil +} diff --git a/commands/root.go b/commands/root.go index 8b830960..82167323 100644 --- a/commands/root.go +++ b/commands/root.go @@ -35,6 +35,8 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) { installCmd(dockerCli), uninstallCmd(dockerCli), versionCmd(dockerCli), + helloCmd(dockerCli), + pruneCmd(dockerCli), imagetoolscmd.RootCmd(dockerCli), ) }