From b95adc87d8bc7b087d4d4cc0eafdf28da7e2ec27 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 23 Mar 2023 20:47:18 +0100 Subject: [PATCH] Made cli.instance.Create function private --- internal/cli/core/search.go | 8 ++------ internal/cli/instance/instance.go | 6 +++--- internal/cli/lib/search.go | 10 +++------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/internal/cli/core/search.go b/internal/cli/core/search.go index ce42c1b41ac..0259d35bf44 100644 --- a/internal/cli/core/search.go +++ b/internal/cli/core/search.go @@ -58,20 +58,16 @@ func initSearchCommand() *cobra.Command { const indexUpdateInterval = "24h" func runSearchCommand(cmd *cobra.Command, args []string) { - inst, status := instance.Create() - if status != nil { - feedback.Fatal(tr("Error creating instance: %v", status), feedback.ErrGeneric) - } + inst := instance.CreateAndInit() if indexesNeedUpdating(indexUpdateInterval) { err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{Instance: inst}, feedback.ProgressBar()) if err != nil { feedback.FatalError(err, feedback.ErrGeneric) } + instance.Init(inst) } - instance.Init(inst) - arguments := strings.ToLower(strings.Join(args, " ")) logrus.Infof("Executing `arduino-cli core search` with args: '%s'", arguments) diff --git a/internal/cli/instance/instance.go b/internal/cli/instance/instance.go index 473aac45fd1..60fbe8b54f7 100644 --- a/internal/cli/instance/instance.go +++ b/internal/cli/instance/instance.go @@ -38,7 +38,7 @@ func CreateAndInit() *rpc.Instance { // If Create fails the CLI prints an error and exits since to execute further operations a valid Instance is mandatory. // If Init returns errors they're printed only. func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc.Instance, *rpc.Profile) { - instance, err := Create() + instance, err := create() if err != nil { feedback.Fatal(tr("Error creating instance: %v", err), feedback.ErrGeneric) } @@ -46,8 +46,8 @@ func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc. return instance, profile } -// Create and return a new Instance. -func Create() (*rpc.Instance, error) { +// create and return a new Instance. +func create() (*rpc.Instance, error) { res, err := commands.Create(&rpc.CreateRequest{}) if err != nil { return nil, err diff --git a/internal/cli/lib/search.go b/internal/cli/lib/search.go index 6b6c745188e..25cc3d6b048 100644 --- a/internal/cli/lib/search.go +++ b/internal/cli/lib/search.go @@ -55,12 +55,9 @@ func initSearchCommand() *cobra.Command { const indexUpdateInterval = 60 * time.Minute func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) { - inst, status := instance.Create() - logrus.Info("Executing `arduino-cli lib search`") + inst := instance.CreateAndInit() - if status != nil { - feedback.Fatal(tr("Error creating instance: %v", status), feedback.ErrGeneric) - } + logrus.Info("Executing `arduino-cli lib search`") if indexNeedsUpdating(indexUpdateInterval) { if err := commands.UpdateLibrariesIndex( @@ -70,10 +67,9 @@ func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) { ); err != nil { feedback.Fatal(tr("Error updating library index: %v", err), feedback.ErrGeneric) } + instance.Init(inst) } - instance.Init(inst) - searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{ Instance: inst, Query: strings.Join(args, " "),