10000 [BREAKING] gRPC / golang Configuration API refactoring by cmaglie · Pull Request #2565 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[BREAKING] gRPC / golang Configuration API refactoring #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8c07823
Moved a batch of function from commands/* subpackage to commands
cmaglie Mar 13, 2024
3d8f50a
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
3ff8e09
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
8615985
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
61e5c46
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
9e75b4d
Removed unused parameters
cmaglie Mar 13, 2024
f1a015c
Removed unused file
cmaglie Mar 13, 2024
c4ca852
Removed ToRPCStatus in favor of standardized GRPCStatus() interface
cmaglie Mar 13, 2024
23ccd43
Inlining methods in ArduinoCoreServiceImpl (part 1: BoardListAll)
cmaglie Mar 13, 2024
53f03e5
Inlining methods in ArduinoCoreServiceImpl (part 2: BoardDetails)
cmaglie Mar 13, 2024
0df2149
Inlining methods in ArduinoCoreServiceImpl (part 3: BoardList)
cmaglie Mar 13, 2024
f65eff2
Inlining methods in ArduinoCoreServiceImpl (part 4: BoardListWatch)
cmaglie Mar 14, 2024
06d6842
Inlining methods in ArduinoCoreServiceImpl (part 5: Create and Destroy)
cmaglie Mar 14, 2024
8bd0eef
Follow convetion where context must be the first argument
cmaglie Mar 14, 2024
a81069d
Inlining methods in ArduinoCoreServiceImpl (part 6: Init)
cmaglie Mar 14, 2024
917dcc5
Inlining methods in ArduinoCoreServiceImpl (part 7: UpdateIndex)
cmaglie Mar 14, 2024
bb815cf
Inlining methods in ArduinoCoreServiceImpl (part 8: Monitor)
cmaglie Mar 15, 2024
0e434f2
Inlining methods in ArduinoCoreServiceImpl (part 9: Compile)
cmaglie Mar 18, 2024
12cf52e
Inlining methods in ArduinoCoreServiceImpl (part 10: PlatformInstall,…
cmaglie Mar 18, 2024
cfe4b27
Inlining methods in ArduinoCoreServiceImpl (part 11: LibraryDownload,…
cmaglie Mar 18, 2024
a3800fa
Inlining methods in ArduinoCoreServiceImpl (part 12: UpdateLibrariesI…
cmaglie Mar 18, 2024
738ad7c
Inlining methods in ArduinoCoreServiceImpl (part 13: NewSketch, LoadS…
cmaglie Mar 18, 2024
0442319
Inlining methods in ArduinoCoreServiceImpl (part 14: Upload, UploadUs…
cmaglie Mar 18, 2024
65ecbaf
Inlining methods in ArduinoCoreServiceImpl (part 15: SupportedUserFie…
cmaglie Mar 18, 2024
0bdc07a
Inlining methods in ArduinoCoreServiceImpl (part 16: CleanDownloadCac…
cmaglie Mar 25, 2024
3193b7c
Made utility functions private and put them in their own file
cmaglie Mar 18, 2024
c08c59e
Run tests forcing the english language
cmaglie Mar 20, 2024
e8e1574
Use correct env var to force configuration in integration test
cmaglie Apr 19, 2024
9bab3c5
Fixed markdown link
cmaglie Apr 19, 2024
6320f6e
Always use arduino-cli in user-agent string
cmaglie Apr 19, 2024
1fddba7
Removed global *viper.Viper settings instance
cmaglie Mar 20, 2024
4c50868
Implementation of Viper replacement library
cmaglie Apr 17, 2024
0453677
Use custom type to avoid context-values collisions
cmaglie Apr 22, 2024
61b66a7
Fixed test
cmaglie Apr 19, 2024
087a6f5
Fixed FindConfigFileInArgsFallbackOnEnv unit test
cmaglie Apr 19, 2024
9cd9c97
Fixed TestUserAgentHeader and TestProxy
cmaglie Apr 19, 2024
384c30c
Improved error message
cmaglie Apr 21, 2024
6aa742f
Config set adds only unique values
cmaglie Apr 21, 2024
0aafda3
Fixed initialization sequence for 'config init' command
cmaglie Apr 21, 2024
921fa61
Config search now looks into ARDUINO_DIRECTORIES_DATA env too
cmaglie Apr 21, 2024
ad8dbd9
Fixed all config* integration test
cmaglie Apr 21, 2024
4061131
Added missing type schema
cmaglie Apr 21, 2024
fa835de
Added docs
cmaglie Apr 23, 2024
72e05ee
Updated documentation about configuration file format
cmaglie Apr 29, 2024
89a79cb
Fixed a small imperfection in test
cmaglie Apr 30, 2024
240c8b3
Pass context in upload and burn-bootloader
cmaglie Apr 30, 2024
24ac040
Pass down context in all places where it's needed
cmaglie Apr 30, 2024
6cf4eb7
Removed unused parameter
cmaglie Apr 30, 2024
27e9c3e
Tolerate errors in invalid config files, and report them as warnings
cmaglie May 2, 2024
7658db6
Improved handling of incomplete configs array
cmaglie May 2, 2024
a58c350
Disable logging until it is setup in the arduino-cli pre-run
cmaglie May 6, 2024
9585728
Show config-load warning after feedback package initialization
cmaglie May 6, 2024
b279d4b
Fixed 'feedback' package initialization order
cmaglie May 6, 2024
278a331
Applied changes from code review
cmaglie May 6, 2024
c355478
Updated client_example
cmaglie May 6, 2024
cec1fdb
Improved array handling in configmap, and unit-tests
cmaglie May 6, 2024
File filter
10000

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inlining methods in ArduinoCoreServiceImpl (part 1: BoardListAll)
This commit is composed of many parts:

* ArduinoCoreServiceImpl has been made private
* A new function NewArduinoCoreService() has been added to instatiate a
  new service.
* The service is created at CLI startup and sent down the initialization
  chain where needed.

In this commit only the BoardListAll command has been ported to prove
the feasability of the change.
  • Loading branch information
cmaglie committed May 6, 2024
commit 23ccd4332dcbe8b8153824381ae79b96de419a20
107 changes: 53 additions & 54 deletions commands/service.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions commands/service_board_listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// BoardListAll FIXMEDOC
func BoardListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) {
// BoardListAll list all the boards provided by installed platforms.
func (s *arduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) {
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions commands/service_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// Debug returns a stream response that can be used to fetch data from the
// target. The first message passed through the `Debug` request must
// contain DebugRequest configuration params, not data.
func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer) error {
func (s *arduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer) error {
// Grab the first message
msg, err := stream.Recv()
if err != nil {
Expand Down Expand Up @@ -61,11 +61,11 @@ func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer)
}

// GetDebugConfig return metadata about a debug session
func (s *ArduinoCoreServerImpl) GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
func (s *arduinoCoreServerImpl) GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
return GetDebugConfig(ctx, req)
}

// IsDebugSupported checks if debugging is supported for a given configuration
func (s *ArduinoCoreServerImpl) IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*rpc.IsDebugSupportedResponse, error) {
func (s *arduinoCoreServerImpl) IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*rpc.IsDebugSupportedResponse, error) {
return IsDebugSupported(ctx, req)
}
12 changes: 6 additions & 6 deletions commands/service_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// SettingsGetAll returns a message with a string field containing all the settings
// currently in use, marshalled in JSON format.
func (s *ArduinoCoreServerImpl) SettingsGetAll(ctx context.Context, req *rpc.SettingsGetAllRequest) (*rpc.SettingsGetAllResponse, error) {
func (s *arduinoCoreServerImpl) SettingsGetAll(ctx context.Context, req *rpc.SettingsGetAllRequest) (*rpc.SettingsGetAllResponse, error) {
b, err := json.Marshal(configuration.Settings.AllSettings())
if err == nil {
return &rpc.SettingsGetAllResponse{
Expand Down Expand Up @@ -68,7 +68,7 @@ func mapper(toMap map[string]interface{}) map[string]interface{} {
}

// SettingsMerge applies multiple settings values at once.
func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.SettingsMergeRequest) (*rpc.SettingsMergeResponse, error) {
func (s *arduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.SettingsMergeRequest) (*rpc.SettingsMergeResponse, error) {
var toMerge map[string]interface{}
if err := json.Unmarshal([]byte(req.GetJsonData()), &toMerge); err != nil {
return nil, err
Expand All @@ -93,7 +93,7 @@ func (s *ArduinoCoreServerImpl) SettingsMerge(ctx context.Context, req *rpc.Sett
// SettingsGetValue returns a settings value given its key. If the key is not present
// an error will be returned, so that we distinguish empty settings from missing
// ones.
func (s *ArduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.SettingsGetValueRequest) (*rpc.SettingsGetValueResponse, error) {
func (s *arduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.SettingsGetValueRequest) (*rpc.SettingsGetValueResponse, error) {
key := req.GetKey()

// Check if settings key actually existing, we don't use Viper.InConfig()
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *ArduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.S
}

// SettingsSetValue updates or set a value for a certain key.
func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.SettingsSetValueRequest) (*rpc.SettingsSetValueResponse, error) {
func (s *arduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.SettingsSetValueRequest) (*rpc.SettingsSetValueResponse, error) {
key := val.GetKey()
var value interface{}

Expand All @@ -137,15 +137,15 @@ func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.S
// We don't have a Read() function, that's not necessary since we only want one config file to be used
// and that's picked up when the CLI is run as daemon, either using the default path or a custom one
// set with the --config-file flag.
func (s *ArduinoCoreServerImpl) SettingsWrite(ctx context.Context, req *rpc.SettingsWriteRequest) (*rpc.SettingsWriteResponse, error) {
func (s *arduinoCoreServerImpl) SettingsWrite(ctx context.Context, req *rpc.SettingsWriteRequest) (*rpc.SettingsWriteResponse, error) {
if err := configuration.Settings.WriteConfigAs(req.GetFilePath()); err != nil {
return nil, err
}
return &rpc.SettingsWriteResponse{}, nil
}

// SettingsDelete removes a key from the config file
func (s *ArduinoCoreServerImpl) SettingsDelete(ctx context.Context, req *rpc.SettingsDeleteRequest) (*rpc.SettingsDeleteResponse, error) {
func (s *arduinoCoreServerImpl) SettingsDelete(ctx context.Context, req *rpc.SettingsDeleteRequest) (*rpc.SettingsDeleteResponse, error) {
toDelete := req.GetKey()

// Check if settings key actually existing, we don't use Viper.InConfig()
Expand Down
2 changes: 1 addition & 1 deletion commands/service_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/stretchr/testify/require"
)

var svc = ArduinoCoreServerImpl{}
var svc = NewArduinoCoreServer("")

func init() {
configuration.Settings = configuration.Init(filepath.Join("testdata", "arduino-cli.yaml"))
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
// GetInstalledBoards is an helper function useful to autocomplete.
// It returns a list of fqbn
// it's taken from cli/board/listall.go
func GetInstalledBoards() []string {
func GetInstalledBoards(srv rpc.ArduinoCoreServiceServer) []string {
inst := instance.CreateAndInit()

list, _ := commands.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
list, _ := srv.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: nil,
IncludeHiddenBoards: false,
Expand All @@ -44,7 +44,7 @@ func GetInstalledBoards() []string {

// GetInstalledProgrammers is an helper function useful to autocomplete.
// It returns a list of programmers available based on the installed boards
func GetInstalledProgrammers() []string {
func GetInstalledProgrammers(srv rpc.ArduinoCoreServiceServer) []string {
inst := instance.CreateAndInit()

// we need the list of the available fqbn in order to get the list of the programmers
Expand All @@ -53,7 +53,7 @@ func GetInstalledProgrammers() []string {
SearchArgs: nil,
IncludeHiddenBoards: false,
}
list, _ := commands.BoardListAll(context.Background(), listAllReq)
list, _ := srv.BoardListAll(context.Background(), listAllReq)

installedProgrammers := make(map[string]string)
for _, board := range list.GetBoards() {
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/arguments/fqbn.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type Fqbn struct {
}

// AddToCommand adds the flags used to set fqbn to the specified Command
func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
func (f *Fqbn) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer) {
cmd.Flags().StringVarP(&f.fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return GetInstalledBoards(), cobra.ShellCompDirectiveDefault
return GetInstalledBoards(srv), cobra.ShellCompDirectiveDefault
})
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/arguments/programmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type Programmer struct {
}

// AddToCommand adds the flags used to set the programmer to the specified Command
func (p *Programmer) AddToCommand(cmd *cobra.Command) {
func (p *Programmer) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer) {
cmd.Flags().StringVarP(&p.programmer, "programmer", "P", "", tr("Programmer to use, e.g: atmel_ice"))
cmd.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
return GetInstalledProgrammers(srv), cobra.ShellCompDirectiveDefault
})
}

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/spf13/cobra"
)

func initAttachCommand() *cobra.Command {
func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var port arguments.Port
var fqbn arguments.Fqbn
var programmer arguments.Programmer
Expand All @@ -48,9 +48,9 @@ func initAttachCommand() *cobra.Command {
runAttachCommand(sketchPath, &port, fqbn.String(), &programmer)
},
}
fqbn.AddToCommand(attachCommand)
fqbn.AddToCommand(attachCommand, srv)
port.AddToCommand(attachCommand)
programmer.AddToCommand(attachCommand)
programmer.AddToCommand(attachCommand, srv)

return attachCommand
}
Expand Down
11 changes: 6 additions & 5 deletions internal/cli/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import (
"os"

"github.com/arduino/arduino-cli/internal/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
)

var tr = i18n.Tr

// NewCommand created a new `board` command
func NewCommand() *cobra.Command {
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
boardCommand := &cobra.Command{
Use: "board",
Short: tr("Arduino board commands."),
Expand All @@ -34,10 +35,10 @@ func NewCommand() *cobra.Command {
" " + os.Args[0] + " board list",
}

boardCommand.AddCommand(initAttachCommand())
boardCommand.AddCommand(initDetailsCommand())
boardCommand.AddCommand(initListCommand())
boardCommand.AddCommand(initListAllCommand())
boardCommand.AddCommand(initAttachCommand(srv))
boardCommand.AddCommand(initDetailsCommand(srv))
boardCommand.AddCommand(initListCommand(srv))
boardCommand.AddCommand(initListAllCommand(srv))
boardCommand.AddCommand(initSearchCommand())

return boardCommand
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/spf13/cobra"
)

func initDetailsCommand() *cobra.Command {
func initDetailsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var showFullDetails bool
var listProgrammers bool
var fqbn arguments.Fqbn
Expand All @@ -48,7 +48,7 @@ func initDetailsCommand() *cobra.Command {
},
}

fqbn.AddToCommand(detailsCommand)
fqbn.AddToCommand(detailsCommand, srv)
detailsCommand.Flags().BoolVarP(&showFullDetails, "full", "f", false, tr("Show full board details"))
detailsCommand.Flags().BoolVarP(&listProgrammers, "list-programmers", "", false, tr("Show list of available programmers"))
detailsCommand.MarkFlagRequired("fqbn")
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/spf13/cobra"
)

func initListCommand() *cobra.Command {
func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var timeoutArg arguments.DiscoveryTimeout
var watch bool
var fqbn arguments.Fqbn
Expand All @@ -51,7 +51,7 @@ func initListCommand() *cobra.Command {
}

timeoutArg.AddToCommand(listCommand)
fqbn.AddToCommand(listCommand)
fqbn.AddToCommand(listCommand, srv)
listCommand.Flags().BoolVarP(&watch, "watch", "w", false, tr("Command keeps running and prints list of connected boards whenever there is a change."))
return listCommand
}
Expand Down
11 changes: 6 additions & 5 deletions internal/cli/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"sort"

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
"github.com/arduino/arduino-cli/internal/cli/feedback/table"
Expand All @@ -33,7 +32,7 @@ import (

var showHiddenBoard bool

func initListAllCommand() *cobra.Command {
func initListAllCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var listAllCommand = &cobra.Command{
Use: fmt.Sprintf("listall [%s]", tr("boardname")),
Short: tr("List all known boards and their corresponding FQBN."),
Expand All @@ -43,19 +42,21 @@ for a specific board if you specify the board name`),
" " + os.Args[0] + " board listall\n" +
" " + os.Args[0] + " board listall zero",
Args: cobra.ArbitraryArgs,
Run: runListAllCommand,
Run: func(cmd *cobra.Command, args []string) {
runListAllCommand(args, srv)
},
}
listAllCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
return listAllCommand
}

// runListAllCommand list all installed boards
func runListAllCommand(cmd *cobra.Command, args []string) {
func runListAllCommand(args []string, srv rpc.ArduinoCoreServiceServer) {
inst := instance.CreateAndInit()

logrus.Info("Executing `arduino-cli board listall`")

list, err := commands.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
list, err := srv.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: args,
IncludeHiddenBoards: showHiddenBoard,
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
)

// NewCommand created a new `burn-bootloader` command
func NewCommand() *cobra.Command {
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
burnBootloaderCommand := &cobra.Command{
Use: "burn-bootloader",
Short: tr("Upload the bootloader."),
Expand All @@ -52,9 +52,9 @@ func NewCommand() *cobra.Command {
Run: runBootloaderCommand,
}

fqbn.AddToCommand(burnBootloaderCommand)
fqbn.AddToCommand(burnBootloaderCommand, srv)
port.AddToCommand(burnBootloaderCommand)
programmer.AddToCommand(burnBootloaderCommand)
programmer.AddToCommand(burnBootloaderCommand, srv)
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Turns on verbose mode."))
burnBootloaderCommand.Flags().BoolVar(&dryRun, "dry-run", false, tr("Do not perform the actual upload, just log out actions"))
Expand Down
30 changes: 12 additions & 18 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ var (
)

// NewCommand creates a new ArduinoCli command root
func NewCommand() *cobra.Command {
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
cobra.AddTemplateFunc("tr", i18n.Tr)

var updaterMessageChan chan *semver.Version

// ArduinoCli is the root command
arduinoCli := &cobra.Command{
cmd := &cobra.Command{
Use: "arduino-cli",
Short: tr("Arduino CLI."),
Long: tr("Arduino Command Line Interface (arduino-cli)."),
Expand Down Expand Up @@ -112,35 +112,27 @@ func NewCommand() *cobra.Command {
},
}

arduinoCli.SetUsageTemplate(getUsageTemplate())
cmd.SetUsageTemplate(getUsageTemplate())

createCliCommandTree(arduinoCli)

return arduinoCli
}

// this is here only for testing
func createCliCommandTree(cmd *cobra.Command) {
cmd.AddCommand(board.NewCommand())
cmd.AddCommand(board.NewCommand(srv))
cmd.AddCommand(cache.NewCommand())
cmd.AddCommand(compile.NewCommand())
cmd.AddCommand(compile.NewCommand(srv))
cmd.AddCommand(completion.NewCommand())
cmd.AddCommand(config.NewCommand())
cmd.AddCommand(core.NewCommand())
cmd.AddCommand(daemon.NewCommand())
cmd.AddCommand(generatedocs.NewCommand())
cmd.AddCommand(lib.NewCommand())
cmd.AddCommand(monitor.NewCommand())
cmd.AddCommand(lib.NewCommand(srv))
cmd.AddCommand(monitor.NewCommand(srv))
cmd.AddCommand(outdated.NewCommand())
cmd.AddCommand(sketch.NewCommand())
cmd.AddCommand(update.NewCommand())
cmd.AddCommand(upgrade.NewCommand())
cmd.AddCommand(upload.NewCommand())
cmd.AddCommand(debug.NewCommand())
cmd.AddCommand(burnbootloader.NewCommand())
cmd.AddCommand(upload.NewCommand(srv))
cmd.AddCommand(debug.NewCommand(srv))
cmd.AddCommand(burnbootloader.NewCommand(srv))
cmd.AddCommand(version.NewCommand())
cmd.AddCommand(feedback.NewCommand())

cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, tr("Print the logs on the standard output."))
cmd.Flag("verbose").Hidden = true
cmd.PersistentFlags().BoolVar(&verbose, "log", false, tr("Print the logs on the standard output."))
Expand All @@ -166,6 +158,8 @@ func createCliCommandTree(cmd *cobra.Command) {
cmd.PersistentFlags().StringSlice("additional-urls", []string{}, tr("Comma-separated list of additional URLs for the Boards Manager."))
cmd.PersistentFlags().Bool("no-color", false, "Disable colored output.")
configuration.BindFlags(cmd, configuration.Settings)

return cmd
}

// convert the string passed to the `--log-level` option to the corresponding
Expand Down
Loading
0