From 444379e2d76ca81380475e055b46149c335b1155 Mon Sep 17 00:00:00 2001 From: "emily.johnson" Date: Fri, 26 Feb 2021 13:11:10 -0600 Subject: [PATCH] Check error return for MarkFlagRequired --- cargo/jam/commands/pack.go | 10 ++++++++-- cargo/jam/commands/summarize.go | 5 ++++- cargo/jam/commands/update_builder.go | 6 +++++- cargo/jam/commands/update_buildpack.go | 11 +++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cargo/jam/commands/pack.go b/cargo/jam/commands/pack.go index 24eb866c..14379598 100644 --- a/cargo/jam/commands/pack.go +++ b/cargo/jam/commands/pack.go @@ -36,8 +36,14 @@ func pack() *cobra.Command { cmd.Flags().BoolVar(&flags.offline, "offline", false, "enable offline caching of dependencies") cmd.Flags().StringVar(&flags.stack, "stack", "", "restricts dependencies to given stack") - cmd.MarkFlagRequired("buildpack") - cmd.MarkFlagRequired("version") + err := cmd.MarkFlagRequired("buildpack") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark buildpack flag as required") + } + err = cmd.MarkFlagRequired("version") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark version flag as required") + } return cmd } diff --git a/cargo/jam/commands/summarize.go b/cargo/jam/commands/summarize.go index 64aceaae..8d8e64d0 100644 --- a/cargo/jam/commands/summarize.go +++ b/cargo/jam/commands/summarize.go @@ -24,7 +24,10 @@ func summarize() *cobra.Command { cmd.Flags().StringVar(&flags.buildpackTarballPath, "buildpack", "", "path to a buildpackage tarball (required)") cmd.Flags().StringVar(&flags.format, "format", "markdown", "format of output options are (markdown, json)") - cmd.MarkFlagRequired("buildpack") + err := cmd.MarkFlagRequired("buildpack") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark buildpack flag as required") + } return cmd } diff --git a/cargo/jam/commands/update_builder.go b/cargo/jam/commands/update_builder.go index 46233aa0..0b1d970e 100644 --- a/cargo/jam/commands/update_builder.go +++ b/cargo/jam/commands/update_builder.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/spf13/cobra" + "os" ) type updateBuilderFlags struct { @@ -23,7 +24,10 @@ func updateBuilder() *cobra.Command { cmd.Flags().StringVar(&flags.builderFile, "builder-file", "", "path to the builder.toml file (required)") cmd.Flags().StringVar(&flags.lifecycleURI, "lifecycle-uri", "index.docker.io/buildpacksio/lifecycle", "URI for lifecycle image (optional: default=index.docker.io/buildpacksio/lifecycle)") - cmd.MarkFlagRequired("builder-file") + err := cmd.MarkFlagRequired("builder-file") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark builder-file flag as required") + } return cmd } diff --git a/cargo/jam/commands/update_buildpack.go b/cargo/jam/commands/update_buildpack.go index 651230b6..cb430709 100644 --- a/cargo/jam/commands/update_buildpack.go +++ b/cargo/jam/commands/update_buildpack.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/paketo-buildpacks/packit/cargo/jam/internal" "github.com/spf13/cobra" + "os" ) type updateBuildpackFlags struct { @@ -23,8 +24,14 @@ func updateBuildpack() *cobra.Command { cmd.Flags().StringVar(&flags.buildpackFile, "buildpack-file", "", "path to the buildpack.toml file (required)") cmd.Flags().StringVar(&flags.packageFile, "package-file", "", "path to the package.toml file (required)") - cmd.MarkFlagRequired("buildpack-file") - cmd.MarkFlagRequired("package-file") + err := cmd.MarkFlagRequired("buildpack-file") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark buildpack-file flag as required") + } + err = cmd.MarkFlagRequired("package-file") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to mark package-file flag as required") + } return cmd }