Skip to content

Commit

Permalink
Made cli.instance.Create function private
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Mar 23, 2023
1 parent 462ad83 commit b95adc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
8 changes: 2 additions & 6 deletions internal/cli/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ 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)
}
profile := InitWithProfile(instance, profileName, sketchPath)
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
Expand Down
10 changes: 3 additions & 7 deletions internal/cli/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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, " "),
Expand Down

0 comments on commit b95adc8

Please sign in to comment.