summaryrefslogtreecommitdiff
path: root/cmd/podman/images/build.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-13 16:46:51 +0100
committerGitHub <noreply@github.com>2020-11-13 16:46:51 +0100
commit2993e97dec9d998d2eca7c5aee918b1429596a85 (patch)
tree9bdb3b5c766d913a8d1980ad017276e1f1a51b7c /cmd/podman/images/build.go
parent6d9d9fee30b5982858d51a666f0c335ba47323a0 (diff)
parentae3816614de1c2a0c9ab9cd05afebc5b1dda6429 (diff)
downloadpodman-2993e97dec9d998d2eca7c5aee918b1429596a85.tar.gz
podman-2993e97dec9d998d2eca7c5aee918b1429596a85.tar.bz2
podman-2993e97dec9d998d2eca7c5aee918b1429596a85.zip
Merge pull request #6442 from Luap99/podman-autocomplete
Shell completion
Diffstat (limited to 'cmd/podman/images/build.go')
-rw-r--r--cmd/podman/images/build.go39
1 files changed, 25 insertions, 14 deletions
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index ccae25276..c76e4ac80 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -9,6 +9,7 @@ import (
"github.com/containers/buildah/imagebuildah"
buildahCLI "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
@@ -17,7 +18,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
- "github.com/spf13/pflag"
)
// buildFlagsWrapper are local to cmd/ as the build code is using Buildah-internal
@@ -39,22 +39,24 @@ var (
// Command: podman _diff_ Object_ID
buildDescription = "Builds an OCI or Docker image using instructions from one or more Containerfiles and a specified build context directory."
buildCmd = &cobra.Command{
- Use: "build [options] [CONTEXT]",
- Short: "Build an image using instructions from Containerfiles",
- Long: buildDescription,
- Args: cobra.MaximumNArgs(1),
- RunE: build,
+ Use: "build [options] [CONTEXT]",
+ Short: "Build an image using instructions from Containerfiles",
+ Long: buildDescription,
+ Args: cobra.MaximumNArgs(1),
+ RunE: build,
+ ValidArgsFunction: completion.AutocompleteDefault,
Example: `podman build .
podman build --creds=username:password -t imageName -f Containerfile.simple .
podman build --layers --force-rm --tag imageName .`,
}
imageBuildCmd = &cobra.Command{
- Args: buildCmd.Args,
- Use: buildCmd.Use,
- Short: buildCmd.Short,
- Long: buildCmd.Long,
- RunE: buildCmd.RunE,
+ Args: buildCmd.Args,
+ Use: buildCmd.Use,
+ Short: buildCmd.Short,
+ Long: buildCmd.Long,
+ RunE: buildCmd.RunE,
+ ValidArgsFunction: buildCmd.ValidArgsFunction,
Example: `podman image build .
podman image build --creds=username:password -t imageName -f Containerfile.simple .
podman image build --layers --force-rm --tag imageName .`,
@@ -78,22 +80,25 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: buildCmd,
})
- buildFlags(buildCmd.Flags())
+ buildFlags(buildCmd)
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: imageBuildCmd,
Parent: imageCmd,
})
- buildFlags(imageBuildCmd.Flags())
+ buildFlags(imageBuildCmd)
}
-func buildFlags(flags *pflag.FlagSet) {
+func buildFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+
// Podman flags
flags.BoolVarP(&buildOpts.SquashAll, "squash-all", "", false, "Squash all layers into a single layer")
// Bud flags
budFlags := buildahCLI.GetBudFlags(&buildOpts.BudResults)
+
// --pull flag
flag := budFlags.Lookup("pull")
if err := flag.Value.Set("true"); err != nil {
@@ -101,6 +106,9 @@ func buildFlags(flags *pflag.FlagSet) {
}
flag.DefValue = "true"
flags.AddFlagSet(&budFlags)
+ // Add the completion functions
+ budCompletions := buildahCLI.GetBudFlagsCompletions()
+ completion.CompleteCommandFlags(cmd, budCompletions)
// Layer flags
layerFlags := buildahCLI.GetLayerFlags(&buildOpts.LayerResults)
@@ -126,6 +134,9 @@ func buildFlags(flags *pflag.FlagSet) {
os.Exit(1)
}
flags.AddFlagSet(&fromAndBudFlags)
+ // Add the completion functions
+ fromAndBudFlagsCompletions := buildahCLI.GetFromAndBudFlagsCompletions()
+ completion.CompleteCommandFlags(cmd, fromAndBudFlagsCompletions)
_ = flags.MarkHidden("signature-policy")
flags.SetNormalizeFunc(buildahCLI.AliasFlags)
}