Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/docker: add docker "app" command and install/launch/remove subcom… #5240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cli/command/app/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app

import (
"github.com/docker/docker/client"
)

type fakeClient struct {
client.Client
}
77 changes: 77 additions & 0 deletions cli/command/app/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package app

import (
"context"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/container"
"github.com/docker/cli/cli/command/image"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// cliAdapter adds convenience methods to the command.Cli interface
// for building images, running containers, and copying files from containers
type cliAdapter interface {
command.Cli
//
RunBuild(context.Context, *image.BuildOptions) error
RunRun(context.Context, *pflag.FlagSet, *container.RunOptions, *container.ContainerOptions) error
RunCopy(context.Context, *container.CopyOptions) error
}

type dockerCliAdapter struct {
command.Cli
}

func newDockerCliAdapter(c command.Cli) cliAdapter {
return &dockerCliAdapter{
c,
}
}

func (r *dockerCliAdapter) RunBuild(ctx context.Context, buildOpts *image.BuildOptions) error {
return image.RunBuild(ctx, r, buildOpts)
}

func (r *dockerCliAdapter) RunRun(ctx context.Context, flags *pflag.FlagSet, runOpts *container.RunOptions, containerOpts *container.ContainerOptions) error {
return container.RunRun(ctx, r, flags, runOpts, containerOpts)
}

func (r *dockerCliAdapter) RunCopy(ctx context.Context, copyOpts *container.CopyOptions) error {
return container.RunCopy(ctx, r, copyOpts)
}

// NewAppCommand returns a cobra command for `app` subcommands
func NewAppCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "app",
Short: "Manage application with Docker",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewInstallCommand(dockerCli),
NewLaunchCommand(dockerCli),
NewRemoveCommand(dockerCli),
)
return cmd
}

func markFlagsHiddenExcept(cmd *cobra.Command, unhidden ...string) {
contains := func(n string) bool {
for _, v := range unhidden {
if v == n {
return true
}
}
return false
}
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
name := flag.Name
if !contains(name) {
flag.Hidden = true
}
})
}
Loading