1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cli/command/system/df.go
Victor Vieux e98e4a7111 always add but hide experimental cmds and flags
Signed-off-by: Victor Vieux <vieux@docker.com>

update cobra and use Tags

Signed-off-by: Victor Vieux <vieux@docker.com>

allow client to talk to an older server

Signed-off-by: Victor Vieux <vieux@docker.com>
2016-11-08 04:55:27 -08:00

56 lines
1.2 KiB
Go

package system
import (
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/formatter"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type diskUsageOptions struct {
verbose bool
}
// NewDiskUsageCommand creates a new cobra.Command for `docker df`
func NewDiskUsageCommand(dockerCli *command.DockerCli) *cobra.Command {
var opts diskUsageOptions
cmd := &cobra.Command{
Use: "df [OPTIONS]",
Short: "Show docker disk usage",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runDiskUsage(dockerCli, opts)
},
Tags: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.verbose, "verbose", "v", false, "Show detailed information on space usage")
return cmd
}
func runDiskUsage(dockerCli *command.DockerCli, opts diskUsageOptions) error {
du, err := dockerCli.Client().DiskUsage(context.Background())
if err != nil {
return err
}
duCtx := formatter.DiskUsageContext{
Context: formatter.Context{
Output: dockerCli.Out(),
},
LayersSize: du.LayersSize,
Images: du.Images,
Containers: du.Containers,
Volumes: du.Volumes,
Verbose: opts.verbose,
}
duCtx.Write()
return nil
}