Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
4428a46d
Commit
4428a46d
authored
Nov 19, 2021
by
Umberto Baldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factor out init step for instance creation in `update`commands
parent
06e96b9a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
63 deletions
+41
-63
cli/core/update_index.go
cli/core/update_index.go
+1
-18
cli/instance/instance.go
cli/instance/instance.go
+24
-0
cli/lib/update_index.go
cli/lib/update_index.go
+15
-27
cli/update/update.go
cli/update/update.go
+1
-18
No files found.
cli/core/update_index.go
View file @
4428a46d
...
...
@@ -43,24 +43,7 @@ func initUpdateIndexCommand() *cobra.Command {
func
runUpdateIndexCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino core update-index`"
)
// We don't initialize any CoreInstance when updating indexes since we don't need to.
// Also meaningless errors might be returned when calling this command with --additional-urls
// since the CLI would be searching for a corresponding file for the additional urls set
// as argument but none would be obviously found.
inst
,
status
:=
instance
.
Create
()
if
status
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error creating instance: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
// In case this is the first time the CLI is run we need to update indexes
// to make it work correctly, we must do this explicitly in this command since
// we must use instance.Create instead of instance.CreateAndInit for the
// reason stated above.
if
err
:=
instance
.
FirstUpdate
(
inst
);
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error updating indexes: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
inst
:=
instance
.
CreateInstanceAndRunFirstUpdate
()
_
,
err
:=
commands
.
UpdateIndex
(
context
.
Background
(),
&
rpc
.
UpdateIndexRequest
{
Instance
:
inst
,
...
...
cli/instance/instance.go
View file @
4428a46d
...
...
@@ -140,3 +140,27 @@ func FirstUpdate(instance *rpc.Instance) error {
return
nil
}
// CreateInstanceAndRunFirstUpdate creates an instance and runs `FirstUpdate`.
// It is mandatory for all `update-index` commands to call this
func
CreateInstanceAndRunFirstUpdate
()
*
rpc
.
Instance
{
// We don't initialize any CoreInstance when updating indexes since we don't need to.
// Also meaningless errors might be returned when calling this command with --additional-urls
// since the CLI would be searching for a corresponding file for the additional urls set
// as argument but none would be obviously found.
inst
,
status
:=
Create
()
if
status
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error creating instance: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
// In case this is the first time the CLI is run we need to update indexes
// to make it work correctly, we must do this explicitly in this command since
// we must use instance.Create instead of instance.CreateAndInit for the
// reason stated above.
if
err
:=
FirstUpdate
(
inst
);
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error updating indexes: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
return
inst
}
cli/lib/update_index.go
View file @
4428a46d
...
...
@@ -25,35 +25,25 @@ import (
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
rpc
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func
initUpdateIndexCommand
()
*
cobra
.
Command
{
return
&
cobra
.
Command
{
updateIndexCommand
:=
&
cobra
.
Command
{
Use
:
"update-index"
,
Short
:
tr
(
"Updates the libraries index."
),
Long
:
tr
(
"Updates the libraries index to the latest version."
),
Example
:
" "
+
os
.
Args
[
0
]
+
" lib update-index"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// We don't initialize any CoreInstance when updating indexes since we don't need to.
// Also meaningless errors might be returned when calling this command with --additional-urls
// since the CLI would be searching for a corresponding file for the additional urls set
// as argument but none would be obviously found.
inst
,
status
:=
instance
.
Create
()
if
status
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error creating instance: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
Run
:
runUpdateIndexCommand
,
}
return
updateIndexCommand
}
// In case this is the first time the CLI is run we need to update indexes
// to make it work correctly, we must do this explicitly in this command since
// we must use instance.Create instead of instance.CreateAndInit for the
// reason stated above.
if
err
:=
instance
.
FirstUpdate
(
inst
);
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error updating indexes: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
func
runUpdateIndexCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino lib update-index`"
)
inst
:=
instance
.
CreateInstanceAndRunFirstUpdate
()
err
:=
commands
.
UpdateLibrariesIndex
(
context
.
Background
(),
&
rpc
.
UpdateLibrariesIndexRequest
{
Instance
:
inst
,
...
...
@@ -62,6 +52,4 @@ func initUpdateIndexCommand() *cobra.Command {
feedback
.
Errorf
(
tr
(
"Error updating library index: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
},
}
}
cli/update/update.go
View file @
4428a46d
...
...
@@ -53,24 +53,7 @@ var updateFlags struct {
func
runUpdateCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino update`"
)
// We don't initialize any CoreInstance when updating indexes since we don't need to.
// Also meaningless errors might be returned when calling this command with --additional-urls
// since the CLI would be searching for a corresponding file for the additional urls set
// as argument but none would be obviously found.
inst
,
status
:=
instance
.
Create
()
if
status
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error creating instance: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
// In case this is the first time the CLI is run we need to update indexes
// to make it work correctly, we must do this explicitly in this command since
// we must use instance.Create instead of instance.CreateAndInit for the
// reason stated above.
if
err
:=
instance
.
FirstUpdate
(
inst
);
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error updating indexes: %v"
),
status
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
inst
:=
instance
.
CreateInstanceAndRunFirstUpdate
()
err
:=
commands
.
UpdateCoreLibrariesIndex
(
context
.
Background
(),
&
rpc
.
UpdateCoreLibrariesIndexRequest
{
Instance
:
inst
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment