mirror of https://github.com/docker/cli.git
Add nakedret linter.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
6ef0ea82ea
commit
dbd96badb6
|
@ -207,7 +207,8 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
|
||||||
return client.NewClient(host, verStr, httpClient, customHeaders)
|
return client.NewClient(host, verStr, httpClient, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string, err error) {
|
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error) {
|
||||||
|
var host string
|
||||||
switch len(hosts) {
|
switch len(hosts) {
|
||||||
case 0:
|
case 0:
|
||||||
host = os.Getenv("DOCKER_HOST")
|
host = os.Getenv("DOCKER_HOST")
|
||||||
|
@ -217,8 +218,7 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string,
|
||||||
return "", errors.New("Please specify only one -H")
|
return "", errors.New("Please specify only one -H")
|
||||||
}
|
}
|
||||||
|
|
||||||
host, err = dopts.ParseHost(tlsOptions != nil, host)
|
return dopts.ParseHost(tlsOptions != nil, host)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
|
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
|
||||||
|
|
|
@ -52,12 +52,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
||||||
|
|
||||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||||
return
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := dockerCli.Client().ContainersPrune(context.Background(), pruneFilters)
|
report, err := dockerCli.Client().ContainersPrune(context.Background(), pruneFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(report.ContainersDeleted) > 0 {
|
if len(report.ContainersDeleted) > 0 {
|
||||||
|
@ -68,7 +68,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
spaceReclaimed = report.SpaceReclaimed
|
spaceReclaimed = report.SpaceReclaimed
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return spaceReclaimed, output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPrune calls the Container Prune API
|
// RunPrune calls the Container Prune API
|
||||||
|
|
|
@ -200,7 +200,8 @@ func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
|
||||||
return 0.00
|
return 0.00
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64) {
|
func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) {
|
||||||
|
var blkRead, blkWrite uint64
|
||||||
for _, bioEntry := range blkio.IoServiceBytesRecursive {
|
for _, bioEntry := range blkio.IoServiceBytesRecursive {
|
||||||
switch strings.ToLower(bioEntry.Op) {
|
switch strings.ToLower(bioEntry.Op) {
|
||||||
case "read":
|
case "read":
|
||||||
|
@ -209,7 +210,7 @@ func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64)
|
||||||
blkWrite = blkWrite + bioEntry.Value
|
blkWrite = blkWrite + bioEntry.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return blkRead, blkWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) {
|
func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) {
|
||||||
|
|
|
@ -118,11 +118,11 @@ func (ctx *DiskUsageContext) Write() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *DiskUsageContext) verboseWrite() (err error) {
|
func (ctx *DiskUsageContext) verboseWrite() error {
|
||||||
// First images
|
// First images
|
||||||
tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat)
|
tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Output.Write([]byte("Images space usage:\n\n"))
|
ctx.Output.Write([]byte("Images space usage:\n\n"))
|
||||||
|
@ -141,14 +141,14 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ctx.contextFormat(tmpl, &imageContext{
|
err := ctx.contextFormat(tmpl, &imageContext{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
trunc: true,
|
trunc: true,
|
||||||
i: *i,
|
i: *i,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.postFormat(tmpl, newImageContext())
|
ctx.postFormat(tmpl, newImageContext())
|
||||||
|
@ -157,17 +157,14 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
|
||||||
ctx.Output.Write([]byte("\nContainers space usage:\n\n"))
|
ctx.Output.Write([]byte("\nContainers space usage:\n\n"))
|
||||||
tmpl, err = ctx.startSubsection(defaultDiskUsageContainerTableFormat)
|
tmpl, err = ctx.startSubsection(defaultDiskUsageContainerTableFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, c := range ctx.Containers {
|
for _, c := range ctx.Containers {
|
||||||
// Don't display the virtual size
|
// Don't display the virtual size
|
||||||
c.SizeRootFs = 0
|
c.SizeRootFs = 0
|
||||||
err = ctx.contextFormat(tmpl, &containerContext{
|
err := ctx.contextFormat(tmpl, &containerContext{trunc: true, c: *c})
|
||||||
trunc: true,
|
|
||||||
c: *c,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.postFormat(tmpl, newContainerContext())
|
ctx.postFormat(tmpl, newContainerContext())
|
||||||
|
@ -176,21 +173,18 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
|
||||||
ctx.Output.Write([]byte("\nLocal Volumes space usage:\n\n"))
|
ctx.Output.Write([]byte("\nLocal Volumes space usage:\n\n"))
|
||||||
tmpl, err = ctx.startSubsection(defaultDiskUsageVolumeTableFormat)
|
tmpl, err = ctx.startSubsection(defaultDiskUsageVolumeTableFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, v := range ctx.Volumes {
|
for _, v := range ctx.Volumes {
|
||||||
err = ctx.contextFormat(tmpl, &volumeContext{
|
if err := ctx.contextFormat(tmpl, &volumeContext{v: *v}); err != nil {
|
||||||
v: *v,
|
return err
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.postFormat(tmpl, newVolumeContext())
|
ctx.postFormat(tmpl, newVolumeContext())
|
||||||
|
|
||||||
// And build cache
|
// And build cache
|
||||||
fmt.Fprintf(ctx.Output, "\nBuild cache usage: %s\n\n", units.HumanSize(float64(ctx.BuilderSize)))
|
fmt.Fprintf(ctx.Output, "\nBuild cache usage: %s\n\n", units.HumanSize(float64(ctx.BuilderSize)))
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type diskUsageImagesContext struct {
|
type diskUsageImagesContext struct {
|
||||||
|
|
|
@ -128,18 +128,18 @@ func getBuildSharedKey(dir string) (string, error) {
|
||||||
return hex.EncodeToString(s[:]), nil
|
return hex.EncodeToString(s[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryNodeIdentifier() (out string) {
|
func tryNodeIdentifier() string {
|
||||||
out = cliconfig.Dir() // return config dir as default on permission error
|
out := cliconfig.Dir() // return config dir as default on permission error
|
||||||
if err := os.MkdirAll(cliconfig.Dir(), 0700); err == nil {
|
if err := os.MkdirAll(cliconfig.Dir(), 0700); err == nil {
|
||||||
sessionFile := filepath.Join(cliconfig.Dir(), ".buildNodeID")
|
sessionFile := filepath.Join(cliconfig.Dir(), ".buildNodeID")
|
||||||
if _, err := os.Lstat(sessionFile); err != nil {
|
if _, err := os.Lstat(sessionFile); err != nil {
|
||||||
if os.IsNotExist(err) { // create a new file with stored randomness
|
if os.IsNotExist(err) { // create a new file with stored randomness
|
||||||
b := make([]byte, 32)
|
b := make([]byte, 32)
|
||||||
if _, err := rand.Read(b); err != nil {
|
if _, err := rand.Read(b); err != nil {
|
||||||
return
|
return out
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(sessionFile, []byte(hex.EncodeToString(b)), 0600); err != nil {
|
if err := ioutil.WriteFile(sessionFile, []byte(hex.EncodeToString(b)), 0600); err != nil {
|
||||||
return
|
return out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,5 +149,5 @@ func tryNodeIdentifier() (out string) {
|
||||||
return string(dt)
|
return string(dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,12 +65,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
warning = allImageWarning
|
warning = allImageWarning
|
||||||
}
|
}
|
||||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||||
return
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
|
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(report.ImagesDeleted) > 0 {
|
if len(report.ImagesDeleted) > 0 {
|
||||||
|
@ -85,7 +85,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
spaceReclaimed = report.SpaceReclaimed
|
spaceReclaimed = report.SpaceReclaimed
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return spaceReclaimed, output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPrune calls the Image Prune API
|
// RunPrune calls the Image Prune API
|
||||||
|
|
|
@ -50,12 +50,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err e
|
||||||
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
||||||
|
|
||||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||||
return
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := dockerCli.Client().NetworksPrune(context.Background(), pruneFilters)
|
report, err := dockerCli.Client().NetworksPrune(context.Background(), pruneFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(report.NetworksDeleted) > 0 {
|
if len(report.NetworksDeleted) > 0 {
|
||||||
|
@ -65,7 +65,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPrune calls the Network Prune API
|
// RunPrune calls the Network Prune API
|
||||||
|
|
|
@ -57,12 +57,12 @@ type pluginRegistryService struct {
|
||||||
registry.Service
|
registry.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s pluginRegistryService) ResolveRepository(name reference.Named) (repoInfo *registry.RepositoryInfo, err error) {
|
func (s pluginRegistryService) ResolveRepository(name reference.Named) (*registry.RepositoryInfo, error) {
|
||||||
repoInfo, err = s.Service.ResolveRepository(name)
|
repoInfo, err := s.Service.ResolveRepository(name)
|
||||||
if repoInfo != nil {
|
if repoInfo != nil {
|
||||||
repoInfo.Class = "plugin"
|
repoInfo.Class = "plugin"
|
||||||
}
|
}
|
||||||
return
|
return repoInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRegistryService() (registry.Service, error) {
|
func newRegistryService() (registry.Service, error) {
|
||||||
|
|
|
@ -52,12 +52,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
||||||
|
|
||||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||||
return
|
return 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := dockerCli.Client().VolumesPrune(context.Background(), pruneFilters)
|
report, err := dockerCli.Client().VolumesPrune(context.Background(), pruneFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(report.VolumesDeleted) > 0 {
|
if len(report.VolumesDeleted) > 0 {
|
||||||
|
@ -68,7 +68,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
|
||||||
spaceReclaimed = report.SpaceReclaimed
|
spaceReclaimed = report.SpaceReclaimed
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return spaceReclaimed, output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPrune calls the Volume Prune API
|
// RunPrune calls the Volume Prune API
|
||||||
|
|
|
@ -10,6 +10,13 @@ RUN go get -d github.com/alecthomas/gometalinter && \
|
||||||
gometalinter --install && \
|
gometalinter --install && \
|
||||||
rm -rf /go/src/* /go/pkg/*
|
rm -rf /go/src/* /go/pkg/*
|
||||||
|
|
||||||
|
ARG NAKEDRET_SHA=3ddb495a6d63bc9041ba843e7d651cf92639d8cb
|
||||||
|
RUN go get -d github.com/alexkohler/nakedret && \
|
||||||
|
cd /go/src/github.com/alexkohler/nakedret && \
|
||||||
|
git checkout -q "$NAKEDRET_SHA" && \
|
||||||
|
go build -v -o /usr/local/bin/nakedret . && \
|
||||||
|
rm -rf /go/src/* /go/pkg/*
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/docker/cli
|
WORKDIR /go/src/github.com/docker/cli
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
|
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
|
||||||
|
|
|
@ -225,7 +225,7 @@ func parseMDContent(mdString string) (description string, examples string) {
|
||||||
examples = strings.Trim(s, "Examples\n")
|
examples = strings.Trim(s, "Examples\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return description, examples
|
||||||
}
|
}
|
||||||
|
|
||||||
type byName []*cobra.Command
|
type byName []*cobra.Command
|
||||||
|
|
|
@ -7,6 +7,12 @@
|
||||||
"parameter .* always receives"
|
"parameter .* always receives"
|
||||||
],
|
],
|
||||||
"EnableGC": true,
|
"EnableGC": true,
|
||||||
|
"Linters": {
|
||||||
|
"nakedret": {
|
||||||
|
"Command": "nakedret",
|
||||||
|
"Pattern": "^(?P<path>.*?\\.go):(?P<line>\\d+)\\s*(?P<message>.*)$"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"DisableAll": true,
|
"DisableAll": true,
|
||||||
"Enable": [
|
"Enable": [
|
||||||
|
@ -20,6 +26,7 @@
|
||||||
"interfacer",
|
"interfacer",
|
||||||
"lll",
|
"lll",
|
||||||
"misspell",
|
"misspell",
|
||||||
|
"nakedret",
|
||||||
"unconvert",
|
"unconvert",
|
||||||
"unparam",
|
"unparam",
|
||||||
"unused",
|
"unused",
|
||||||
|
|
|
@ -95,12 +95,12 @@ func (n *NetworkOpt) String() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDriverOpt(driverOpt string) (key string, value string, err error) {
|
func parseDriverOpt(driverOpt string) (string, string, error) {
|
||||||
parts := strings.SplitN(driverOpt, "=", 2)
|
parts := strings.SplitN(driverOpt, "=", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
err = fmt.Errorf("invalid key value pair format in driver options")
|
return "", "", fmt.Errorf("invalid key value pair format in driver options")
|
||||||
}
|
}
|
||||||
key = strings.TrimSpace(strings.ToLower(parts[0]))
|
key := strings.TrimSpace(strings.ToLower(parts[0]))
|
||||||
value = strings.TrimSpace(strings.ToLower(parts[1]))
|
value := strings.TrimSpace(strings.ToLower(parts[1]))
|
||||||
return
|
return key, value, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue