Adjust commands to latest compose-go

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-18 09:40:57 +02:00
parent 6e6a11aa73
commit cfbd963c3d
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
8 changed files with 54 additions and 25 deletions

View File

@ -19,7 +19,6 @@ package aci
import (
"context"
"fmt"
"github.com/docker/api/secrets"
"io"
"net/http"
"strconv"
@ -42,6 +41,7 @@ import (
"github.com/docker/api/context/cloud"
"github.com/docker/api/context/store"
"github.com/docker/api/errdefs"
"github.com/docker/api/secrets"
)
const (

View File

@ -18,6 +18,7 @@ package compose
import (
"context"
"github.com/compose-spec/compose-go/cli"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -28,6 +29,21 @@ import (
"github.com/docker/api/errdefs"
)
type composeOptions struct {
Name string
WorkingDir string
ConfigPaths []string
Environment []string
}
func (o *composeOptions) toProjectOptions() (*cli.ProjectOptions, error) {
return cli.NewProjectOptions(o.ConfigPaths,
cli.WithOsEnv,
cli.WithEnv(o.Environment),
cli.WithWorkingDirectory(o.WorkingDir),
cli.WithName(o.Name))
}
// Command returns the compose command with its child commands
func Command() *cobra.Command {
command := &cobra.Command{

View File

@ -20,18 +20,17 @@ import (
"context"
"errors"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra"
"github.com/docker/api/client"
)
func downCommand() *cobra.Command {
opts := cli.ProjectOptions{}
opts := composeOptions{}
downCmd := &cobra.Command{
Use: "down",
RunE: func(cmd *cobra.Command, args []string) error {
return runDown(cmd.Context(), &opts)
return runDown(cmd.Context(), opts)
},
}
downCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -41,7 +40,7 @@ func downCommand() *cobra.Command {
return downCmd
}
func runDown(ctx context.Context, opts *cli.ProjectOptions) error {
func runDown(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx)
if err != nil {
return err
@ -52,5 +51,9 @@ func runDown(ctx context.Context, opts *cli.ProjectOptions) error {
return errors.New("compose not implemented in current context")
}
return composeService.Down(ctx, opts)
options, err := opts.toProjectOptions()
if err != nil {
return err
}
return composeService.Down(ctx, options)
}

View File

@ -21,18 +21,17 @@ import (
"errors"
"os"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra"
"github.com/docker/api/client"
)
func logsCommand() *cobra.Command {
opts := cli.ProjectOptions{}
opts := composeOptions{}
logsCmd := &cobra.Command{
Use: "logs",
RunE: func(cmd *cobra.Command, args []string) error {
return runLogs(cmd.Context(), &opts)
return runLogs(cmd.Context(), opts)
},
}
logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -42,7 +41,7 @@ func logsCommand() *cobra.Command {
return logsCmd
}
func runLogs(ctx context.Context, opts *cli.ProjectOptions) error {
func runLogs(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx)
if err != nil {
return err
@ -53,5 +52,9 @@ func runLogs(ctx context.Context, opts *cli.ProjectOptions) error {
return errors.New("compose not implemented in current context")
}
return composeService.Logs(ctx, opts, os.Stdout)
options, err := opts.toProjectOptions()
if err != nil {
return err
}
return composeService.Logs(ctx, options, os.Stdout)
}

View File

@ -25,18 +25,17 @@ import (
"strings"
"text/tabwriter"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra"
"github.com/docker/api/client"
)
func psCommand() *cobra.Command {
opts := cli.ProjectOptions{}
opts := composeOptions{}
psCmd := &cobra.Command{
Use: "ps",
RunE: func(cmd *cobra.Command, args []string) error {
return runPs(cmd.Context(), &opts)
return runPs(cmd.Context(), opts)
},
}
psCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -46,7 +45,7 @@ func psCommand() *cobra.Command {
return psCmd
}
func runPs(ctx context.Context, opts *cli.ProjectOptions) error {
func runPs(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx)
if err != nil {
return err
@ -57,7 +56,11 @@ func runPs(ctx context.Context, opts *cli.ProjectOptions) error {
return errors.New("compose not implemented in current context")
}
serviceList, err := composeService.Ps(ctx, opts)
options, err := opts.toProjectOptions()
if err != nil {
return err
}
serviceList, err := composeService.Ps(ctx, options)
if err != nil {
return err
}

View File

@ -20,7 +20,6 @@ import (
"context"
"errors"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra"
"github.com/docker/api/client"
@ -28,11 +27,11 @@ import (
)
func upCommand() *cobra.Command {
opts := cli.ProjectOptions{}
opts := composeOptions{}
upCmd := &cobra.Command{
Use: "up",
RunE: func(cmd *cobra.Command, args []string) error {
return runUp(cmd.Context(), &opts)
return runUp(cmd.Context(), opts)
},
}
upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -44,7 +43,7 @@ func upCommand() *cobra.Command {
return upCmd
}
func runUp(ctx context.Context, opts *cli.ProjectOptions) error {
func runUp(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx)
if err != nil {
return err
@ -56,6 +55,10 @@ func runUp(ctx context.Context, opts *cli.ProjectOptions) error {
}
return progress.Run(ctx, func(ctx context.Context) error {
return composeService.Up(ctx, opts)
options, err := opts.toProjectOptions()
if err != nil {
return err
}
return composeService.Up(ctx, options)
})
}

View File

@ -31,6 +31,7 @@ import (
"github.com/docker/api/containers"
"github.com/docker/api/context/cloud"
"github.com/docker/api/errdefs"
"github.com/docker/api/secrets"
)
type apiService struct {