mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
Add comments on exported items, remove example command
Also add `make lint` to run the linter
This commit is contained in:
parent
29737c2a23
commit
24c035e822
26 changed files with 136 additions and 196 deletions
|
|
@ -38,9 +38,7 @@ import (
|
|||
"github.com/docker/api/context/store"
|
||||
)
|
||||
|
||||
type CliContext struct {
|
||||
}
|
||||
|
||||
// ContextCommand manages contexts
|
||||
func ContextCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "context",
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2020 Docker Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
v1 "github.com/docker/api/backend/v1"
|
||||
"github.com/docker/api/client"
|
||||
)
|
||||
|
||||
var ExampleCommand = cobra.Command{
|
||||
Use: "example",
|
||||
Short: "sample command using backend, to be removed later",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
c, err := client.New(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
info, err := c.BackendInformation(ctx, &v1.BackendInformationRequest{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetch backend information")
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(info)
|
||||
},
|
||||
}
|
||||
|
||||
type backendAddressKey struct{}
|
||||
|
||||
func BackendAddress(ctx context.Context) (string, error) {
|
||||
v, ok := ctx.Value(backendAddressKey{}).(string)
|
||||
if !ok {
|
||||
return "", errors.New("no backend address key")
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -17,6 +18,7 @@ type execOpts struct {
|
|||
Tty bool
|
||||
}
|
||||
|
||||
// ExecCommand runs a command in a running container
|
||||
func ExecCommand() *cobra.Command {
|
||||
var opts execOpts
|
||||
cmd := &cobra.Command{
|
||||
|
|
@ -52,7 +54,9 @@ func runExec(ctx context.Context, opts execOpts, name string, command string) er
|
|||
return err
|
||||
}
|
||||
defer func() {
|
||||
con.Reset()
|
||||
if err := con.Reset(); err != nil {
|
||||
fmt.Println("Unable to close the console")
|
||||
}
|
||||
}()
|
||||
|
||||
stdout = con
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ type logsOpts struct {
|
|||
Tail string
|
||||
}
|
||||
|
||||
// LogsCommand fetches and shows logs of a container
|
||||
func LogsCommand() *cobra.Command {
|
||||
var opts logsOpts
|
||||
cmd := &cobra.Command{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/api/client"
|
||||
)
|
||||
|
||||
// PsCommand lists containers
|
||||
var PsCommand = cobra.Command{
|
||||
Use: "ps",
|
||||
Short: "List containers",
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/docker/api/client"
|
||||
)
|
||||
|
||||
// Command runs a container
|
||||
func Command() *cobra.Command {
|
||||
var opts runOpts
|
||||
cmd := &cobra.Command{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type serveOpts struct {
|
|||
address string
|
||||
}
|
||||
|
||||
// ServeCommand returns the command to serve the API
|
||||
func ServeCommand() *cobra.Command {
|
||||
var opts serveOpts
|
||||
cmd := &cobra.Command{
|
||||
|
|
@ -42,9 +43,10 @@ func runServe(ctx context.Context, opts serveOpts) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "listen unix socket")
|
||||
}
|
||||
// nolint
|
||||
defer listener.Close()
|
||||
|
||||
p := proxy.NewContainerApi()
|
||||
p := proxy.NewContainerAPI()
|
||||
|
||||
containersv1.RegisterContainersServer(s, p)
|
||||
cliv1.RegisterCliServer(s, &cliServer{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue