Documentation ¶
Index ¶
Constants ¶
View Source
const ( Name = "lint" Usage = "Analyzes container instructions in Dockerfiles" Alias = "l" )
View Source
const ( FlagTargetType = "target-type" FlagSkipBuildContext = "skip-build-context" FlagBuildContextDir = "build-context-dir" FlagSkipDockerignore = "skip-dockerignore" FlagIncludeCheckLabel = "include-check-label" FlagExcludeCheckLabel = "exclude-check-label" FlagIncludeCheckID = "include-check-id" FlagIncludeCheckIDFile = "include-check-id-file" FlagExcludeCheckID = "exclude-check-id" FlagExcludeCheckIDFile = "exclude-check-id-file" FlagShowNoHits = "show-nohits" FlagShowSnippet = "show-snippet" FlagListChecks = "list-checks" )
Lint command flag names
View Source
const ( FlagLintTargetUsage = "Target Dockerfile path (or container image)" FlagTargetTypeUsage = "Explicitly specify the command target type (values: dockerfile, image)" FlagSkipBuildContextUsage = "Don't try to analyze build context" FlagBuildContextDirUsage = "Explicitly specify the build context directory" FlagSkipDockerignoreUsage = "Don't try to analyze .dockerignore" FlagIncludeCheckLabelUsage = "Include checks with the selected label key:value" FlagExcludeCheckLabelUsage = "Exclude checks with the selected label key:value" FlagIncludeCheckIDUsage = "Check ID to include" FlagIncludeCheckIDFileUsage = "File with check IDs to include" FlagExcludeCheckIDUsage = "Check ID to exclude" FlagExcludeCheckIDFileUsage = "File with check IDs to exclude" FlagShowNoHitsUsage = "Show checks with no matches" FlagShowSnippetUsage = "Show check match snippet" FlagListChecksUsage = "List available checks" )
Lint command flag usage info
Variables ¶
View Source
var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Flags: []cli.Flag{ cflag(commands.FlagTarget), cflag(FlagTargetType), cflag(FlagSkipBuildContext), cflag(FlagBuildContextDir), cflag(FlagSkipDockerignore), cflag(FlagIncludeCheckLabel), cflag(FlagExcludeCheckLabel), cflag(FlagIncludeCheckID), cflag(FlagIncludeCheckIDFile), cflag(FlagExcludeCheckID), cflag(FlagExcludeCheckIDFile), cflag(FlagShowNoHits), cflag(FlagShowSnippet), cflag(FlagListChecks), }, Action: func(ctx *cli.Context) error { xc := app.NewExecutionContext(Name) doListChecks := ctx.Bool(FlagListChecks) targetRef := ctx.String(commands.FlagTarget) if !doListChecks { if targetRef == "" { if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing target Dockerfile") cli.ShowCommandHelp(ctx, Name) return nil } else { targetRef = ctx.Args().First() } } } gcvalues, err := commands.GlobalFlagValues(ctx) if err != nil { xc.Out.Error("param.global", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } targetType := ctx.String(FlagTargetType) doSkipBuildContext := ctx.Bool(FlagSkipBuildContext) buildContextDir := ctx.String(FlagBuildContextDir) doSkipDockerignore := ctx.Bool(FlagSkipDockerignore) includeCheckLabels, err := commands.ParseCheckTags(ctx.StringSlice(FlagIncludeCheckLabel)) if err != nil { xc.Out.Error("param.error.invalid.include.check.labels", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } excludeCheckLabels, err := commands.ParseCheckTags(ctx.StringSlice(FlagExcludeCheckLabel)) if err != nil { xc.Out.Error("param.error.invalid.exclude.check.labels", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } includeCheckIDs, err := commands.ParseTokenSet(ctx.StringSlice(FlagIncludeCheckID)) if err != nil { xc.Out.Error("param.error.invalid.include.check.ids", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } includeCheckIDFile := ctx.String(FlagIncludeCheckIDFile) moreIncludeCheckIDs, err := commands.ParseTokenSetFile(includeCheckIDFile) if err != nil { xc.Out.Error("param.error.invalid.include.check.ids.from.file", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } for k, v := range moreIncludeCheckIDs { includeCheckIDs[k] = v } excludeCheckIDs, err := commands.ParseTokenSet(ctx.StringSlice(FlagExcludeCheckID)) if err != nil { xc.Out.Error("param.error.invalid.exclude.check.ids", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } excludeCheckIDFile := ctx.String(FlagExcludeCheckIDFile) moreExcludeCheckIDs, err := commands.ParseTokenSetFile(excludeCheckIDFile) if err != nil { xc.Out.Error("param.error.invalid.exclude.check.ids.from.file", err.Error()) xc.Out.State("exited", ovars{ "exit.code": -1, }) xc.Exit(-1) } for k, v := range moreExcludeCheckIDs { excludeCheckIDs[k] = v } doShowNoHits := ctx.Bool(FlagShowNoHits) doShowSnippet := ctx.Bool(FlagShowSnippet) OnCommand( xc, gcvalues, targetRef, targetType, doSkipBuildContext, buildContextDir, doSkipDockerignore, includeCheckLabels, excludeCheckLabels, includeCheckIDs, excludeCheckIDs, doShowNoHits, doShowSnippet, doListChecks) return nil }, }
View Source
var CommandFlagSuggestions = &commands.FlagSuggestions{ Names: []prompt.Suggest{ {Text: commands.FullFlagName(commands.FlagTarget), Description: FlagLintTargetUsage}, {Text: commands.FullFlagName(FlagTargetType), Description: FlagTargetTypeUsage}, {Text: commands.FullFlagName(FlagSkipBuildContext), Description: FlagSkipBuildContextUsage}, {Text: commands.FullFlagName(FlagBuildContextDir), Description: FlagBuildContextDirUsage}, {Text: commands.FullFlagName(FlagSkipDockerignore), Description: FlagSkipDockerignoreUsage}, {Text: commands.FullFlagName(FlagIncludeCheckLabel), Description: FlagIncludeCheckLabelUsage}, {Text: commands.FullFlagName(FlagExcludeCheckLabel), Description: FlagExcludeCheckLabelUsage}, {Text: commands.FullFlagName(FlagIncludeCheckID), Description: FlagIncludeCheckIDUsage}, {Text: commands.FullFlagName(FlagIncludeCheckIDFile), Description: FlagIncludeCheckIDFileUsage}, {Text: commands.FullFlagName(FlagExcludeCheckID), Description: FlagExcludeCheckIDUsage}, {Text: commands.FullFlagName(FlagExcludeCheckIDFile), Description: FlagExcludeCheckIDFileUsage}, {Text: commands.FullFlagName(FlagShowNoHits), Description: FlagShowNoHitsUsage}, {Text: commands.FullFlagName(FlagShowSnippet), Description: FlagShowSnippetUsage}, {Text: commands.FullFlagName(FlagListChecks), Description: FlagListChecksUsage}, }, Values: map[string]commands.CompleteValue{ commands.FullFlagName(commands.FlagTarget): completeLintTarget, commands.FullFlagName(FlagTargetType): completeLintTargetType, commands.FullFlagName(FlagSkipBuildContext): commands.CompleteBool, commands.FullFlagName(FlagBuildContextDir): commands.CompleteFile, commands.FullFlagName(FlagSkipDockerignore): commands.CompleteBool, commands.FullFlagName(FlagIncludeCheckID): completeLintCheckID, commands.FullFlagName(FlagIncludeCheckIDFile): commands.CompleteFile, commands.FullFlagName(FlagExcludeCheckID): completeLintCheckID, commands.FullFlagName(FlagExcludeCheckIDFile): commands.CompleteFile, commands.FullFlagName(FlagShowNoHits): commands.CompleteBool, commands.FullFlagName(FlagShowSnippet): commands.CompleteTBool, commands.FullFlagName(FlagListChecks): commands.CompleteBool, }, }
View Source
var CommandSuggestion = prompt.Suggest{ Text: Name, Description: Usage, }
View Source
var Flags = map[string]cli.Flag{ commands.FlagTarget: &cli.StringFlag{ Name: commands.FlagTarget, Value: "", Usage: FlagLintTargetUsage, EnvVars: []string{"DSLIM_TARGET"}, }, FlagTargetType: &cli.StringFlag{ Name: FlagTargetType, Value: "", Usage: FlagTargetTypeUsage, EnvVars: []string{"DSLIM_LINT_TARGET_TYPE"}, }, FlagSkipBuildContext: &cli.BoolFlag{ Name: FlagSkipBuildContext, Usage: FlagSkipBuildContextUsage, EnvVars: []string{"DSLIM_LINT_SKIP_BC"}, }, FlagBuildContextDir: &cli.StringFlag{ Name: FlagBuildContextDir, Value: "", Usage: FlagBuildContextDirUsage, EnvVars: []string{"DSLIM_LINT_BC_DIR"}, }, FlagSkipDockerignore: &cli.BoolFlag{ Name: FlagSkipDockerignore, Usage: FlagSkipDockerignoreUsage, EnvVars: []string{"DSLIM_LINT_SKIP_DI"}, }, FlagIncludeCheckLabel: &cli.StringSliceFlag{ Name: FlagIncludeCheckLabel, Value: cli.NewStringSlice(""), Usage: FlagIncludeCheckLabelUsage, EnvVars: []string{"DSLIM_LINT_INCLUDE_LABEL"}, }, FlagExcludeCheckLabel: &cli.StringSliceFlag{ Name: FlagExcludeCheckLabel, Value: cli.NewStringSlice(""), Usage: FlagExcludeCheckLabelUsage, EnvVars: []string{"DSLIM_LINT_EXCLUDE_LABEL"}, }, FlagIncludeCheckID: &cli.StringSliceFlag{ Name: FlagIncludeCheckID, Value: cli.NewStringSlice(""), Usage: FlagIncludeCheckIDUsage, EnvVars: []string{"DSLIM_LINT_INCLUDE_CID"}, }, FlagIncludeCheckIDFile: &cli.StringFlag{ Name: FlagIncludeCheckIDFile, Value: "", Usage: FlagIncludeCheckIDFileUsage, EnvVars: []string{"DSLIM_LINT_INCLUDE_CID_FILE"}, }, FlagExcludeCheckID: &cli.StringSliceFlag{ Name: FlagExcludeCheckID, Value: cli.NewStringSlice(""), Usage: FlagExcludeCheckIDUsage, EnvVars: []string{"DSLIM_LINT_EXCLUDE_CID"}, }, FlagExcludeCheckIDFile: &cli.StringFlag{ Name: FlagExcludeCheckIDFile, Value: "", Usage: FlagExcludeCheckIDFileUsage, EnvVars: []string{"DSLIM_LINT_EXCLUDE_CID_FILE"}, }, FlagShowNoHits: &cli.BoolFlag{ Name: FlagShowNoHits, Usage: FlagShowNoHitsUsage, EnvVars: []string{"DSLIM_LINT_SHOW_NOHITS"}, }, FlagShowSnippet: &cli.BoolFlag{ Name: FlagShowSnippet, Value: true, Usage: FlagShowSnippetUsage, EnvVars: []string{"DSLIM_LINT_SHOW_SNIPPET"}, }, FlagListChecks: &cli.BoolFlag{ Name: FlagListChecks, Usage: FlagListChecksUsage, EnvVars: []string{"DSLIM_LINT_LIST_CHECKS"}, }, }
Functions ¶
func OnCommand ¶
func OnCommand( xc *app.ExecutionContext, gparams *commands.GenericParams, targetRef string, targetType string, doSkipBuildContext bool, buildContextDir string, doSkipDockerignore bool, includeCheckLabels map[string]string, excludeCheckLabels map[string]string, includeCheckIDs map[string]struct{}, excludeCheckIDs map[string]struct{}, doShowNoHits bool, doShowSnippet bool, doListChecks bool)
OnCommand implements the 'lint' docker-slim command
func RegisterCommand ¶
func RegisterCommand()
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.