From 5c72e097fee2657f23ddb7ad9977c26a90f3e45c Mon Sep 17 00:00:00 2001 From: Sourabh Mehta Date: Fri, 28 Jun 2024 11:54:54 +0200 Subject: [PATCH 1/2] Make -S,--context-set as mandatory arg for setup command --- cmd/cbuild/commands/setup/setup.go | 8 +++++++- cmd/cbuild/main.go | 7 +------ pkg/errutils/errutils.go | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/cbuild/commands/setup/setup.go b/cmd/cbuild/commands/setup/setup.go index 1d76ef0..c83059c 100644 --- a/cmd/cbuild/commands/setup/setup.go +++ b/cmd/cbuild/commands/setup/setup.go @@ -72,6 +72,12 @@ func setUpProject(cmd *cobra.Command, args []string) error { useCbuild2CMake = false } + if !useContextSet { + err = errutils.New(errutils.ErrMissingRequiredArg) + log.Error(err) + return err + } + options := builder.Options{ LogFile: logFile, Generator: generator, @@ -137,7 +143,7 @@ func init() { SetUpCmd.Flags().StringP("generator", "g", "Ninja", "Select build system generator") SetUpCmd.Flags().StringSliceP("context", "c", []string{}, "Input context names [][.][+]") SetUpCmd.Flags().StringP("load", "l", "", "Set policy for packs loading [latest | all | required]") - SetUpCmd.Flags().IntP("jobs", "j", 0, "Number of job slots for parallel execution") + SetUpCmd.Flags().IntP("jobs", "j", 8, "Number of job slots for parallel execution") SetUpCmd.Flags().StringP("target", "t", "", "Optional CMake target name") SetUpCmd.Flags().BoolP("schema", "s", true, "Validate project input file(s) against schema") SetUpCmd.Flags().StringP("log", "", "", "Save output messages in a log file") diff --git a/cmd/cbuild/main.go b/cmd/cbuild/main.go index 599658a..3c849ec 100644 --- a/cmd/cbuild/main.go +++ b/cmd/cbuild/main.go @@ -9,7 +9,6 @@ package main import ( "fmt" "os" - "os/exec" "github.com/Open-CMSIS-Pack/cbuild/v2/cmd/cbuild/commands" log "github.com/sirupsen/logrus" @@ -25,11 +24,7 @@ func main() { cmd := commands.NewRootCmd() err := cmd.Execute() if err != nil { - if exitError, ok := err.(*exec.ExitError); ok { - os.Exit(exitError.ExitCode()) - } else { - os.Exit(1) - } + os.Exit(1) } else { os.Exit(0) } diff --git a/pkg/errutils/errutils.go b/pkg/errutils/errutils.go index e21996d..34afa01 100644 --- a/pkg/errutils/errutils.go +++ b/pkg/errutils/errutils.go @@ -28,6 +28,7 @@ const ( ErrRequireArg = "command requires an input file argument. Run '%s' for more information about a command" ErrInvalidVersionString = "invalid version %s. Expected %s" ErrInvalidNumJobs = "invalid number of job slots specified for parallel execution. Expected: j>0" + ErrMissingRequiredArg = "missing required argument. Use --context-set option" ) const ( From b19e3fcf826e9caec827f69bd54d43120bb19e74 Mon Sep 17 00:00:00 2001 From: Sourabh Mehta <73165318+soumeh01@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:38:50 +0200 Subject: [PATCH 2/2] Addressed review comment --- pkg/errutils/errutils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/errutils/errutils.go b/pkg/errutils/errutils.go index 34afa01..c5fe3e5 100644 --- a/pkg/errutils/errutils.go +++ b/pkg/errutils/errutils.go @@ -28,7 +28,7 @@ const ( ErrRequireArg = "command requires an input file argument. Run '%s' for more information about a command" ErrInvalidVersionString = "invalid version %s. Expected %s" ErrInvalidNumJobs = "invalid number of job slots specified for parallel execution. Expected: j>0" - ErrMissingRequiredArg = "missing required argument. Use --context-set option" + ErrMissingRequiredArg = "setup command is missing mandatory option '--context-set'" ) const (