Skip to content

Commit b95adc8

Browse files
committed
Made cli.instance.Create function private
1 parent 462ad83 commit b95adc8

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

Diff for: internal/cli/core/search.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,16 @@ func initSearchCommand() *cobra.Command {
5858
const indexUpdateInterval = "24h"
5959

6060
func runSearchCommand(cmd *cobra.Command, args []string) {
61-
inst, status := instance.Create()
62-
if status != nil {
63-
feedback.Fatal(tr("Error creating instance: %v", status), feedback.ErrGeneric)
64-
}
61+
inst := instance.CreateAndInit()
6562

6663
if indexesNeedUpdating(indexUpdateInterval) {
6764
err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{Instance: inst}, feedback.ProgressBar())
6865
if err != nil {
6966
feedback.FatalError(err, feedback.ErrGeneric)
7067
}
68+
instance.Init(inst)
7169
}
7270

73-
instance.Init(inst)
74-
7571
arguments := strings.ToLower(strings.Join(args, " "))
7672
logrus.Infof("Executing `arduino-cli core search` with args: '%s'", arguments)
7773

Diff for: internal/cli/instance/instance.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ func CreateAndInit() *rpc.Instance {
3838
// If Create fails the CLI prints an error and exits since to execute further operations a valid Instance is mandatory.
3939
// If Init returns errors they're printed only.
4040
func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc.Instance, *rpc.Profile) {
41-
instance, err := Create()
41+
instance, err := create()
4242
if err != nil {
4343
feedback.Fatal(tr("Error creating instance: %v", err), feedback.ErrGeneric)
4444
}
4545
profile := InitWithProfile(instance, profileName, sketchPath)
4646
return instance, profile
4747
}
4848

49-
// Create and return a new Instance.
50-
func Create() (*rpc.Instance, error) {
49+
// create and return a new Instance.
50+
func create() (*rpc.Instance, error) {
5151
res, err := commands.Create(&rpc.CreateRequest{})
5252
if err != nil {
5353
return nil, err

Diff for: internal/cli/lib/search.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ func initSearchCommand() *cobra.Command {
5555
const indexUpdateInterval = 60 * time.Minute
5656

5757
func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) {
58-
inst, status := instance.Create()
59-
logrus.Info("Executing `arduino-cli lib search`")
58+
inst := instance.CreateAndInit()
6059

61-
if status != nil {
62-
feedback.Fatal(tr("Error creating instance: %v", status), feedback.ErrGeneric)
63-
}
60+
logrus.Info("Executing `arduino-cli lib search`")
6461

6562
if indexNeedsUpdating(indexUpdateInterval) {
6663
if err := commands.UpdateLibrariesIndex(
@@ -70,10 +67,9 @@ func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) {
7067
); err != nil {
7168
feedback.Fatal(tr("Error updating library index: %v", err), feedback.ErrGeneric)
7269
}
70+
instance.Init(inst)
7371
}
7472

75-
instance.Init(inst)
76-
7773
searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
7874
Instance: inst,
7975
Query: strings.Join(args, " "),

0 commit comments

Comments
 (0)