Commit 3ff8e090 authored by Cristian Maglie's avatar Cristian Maglie

Moved a batch of function from commands/* subpackage to commands (part 3)

parent 3d8f50a5
...@@ -27,7 +27,6 @@ import ( ...@@ -27,7 +27,6 @@ import (
"github.com/arduino/arduino-cli/commands/monitor" "github.com/arduino/arduino-cli/commands/monitor"
"github.com/arduino/arduino-cli/commands/sketch" "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/updatecheck" "github.com/arduino/arduino-cli/commands/updatecheck"
"github.com/arduino/arduino-cli/commands/upload"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
...@@ -299,7 +298,7 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin ...@@ -299,7 +298,7 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin
Message: &rpc.UploadResponse_ErrStream{ErrStream: data}, Message: &rpc.UploadResponse_ErrStream{ErrStream: data},
}) })
}) })
res, err := upload.Upload(stream.Context(), req, outStream, errStream) res, err := Upload(stream.Context(), req, outStream, errStream)
outStream.Close() outStream.Close()
errStream.Close() errStream.Close()
if res != nil { if res != nil {
...@@ -329,7 +328,7 @@ func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgra ...@@ -329,7 +328,7 @@ func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgra
}, },
}) })
}) })
err := upload.UsingProgrammer(stream.Context(), req, outStream, errStream) err := UploadUsingProgrammer(stream.Context(), req, outStream, errStream)
outStream.Close() outStream.Close()
errStream.Close() errStream.Close()
if err != nil { if err != nil {
...@@ -340,7 +339,7 @@ func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgra ...@@ -340,7 +339,7 @@ func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgra
// SupportedUserFields FIXMEDOC // SupportedUserFields FIXMEDOC
func (s *ArduinoCoreServerImpl) SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) { func (s *ArduinoCoreServerImpl) SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) {
res, err := upload.SupportedUserFields(ctx, req) res, err := SupportedUserFields(ctx, req)
return res, convertErrorToRPCStatus(err) return res, convertErrorToRPCStatus(err)
} }
...@@ -361,7 +360,7 @@ func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, s ...@@ -361,7 +360,7 @@ func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, s
}, },
}) })
}) })
resp, err := upload.BurnBootloader(stream.Context(), req, outStream, errStream) resp, err := BurnBootloader(stream.Context(), req, outStream, errStream)
outStream.Close() outStream.Close()
errStream.Close() errStream.Close()
if err != nil { if err != nil {
...@@ -372,7 +371,7 @@ func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, s ...@@ -372,7 +371,7 @@ func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, s
// ListProgrammersAvailableForUpload FIXMEDOC // ListProgrammersAvailableForUpload FIXMEDOC
func (s *ArduinoCoreServerImpl) ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) { func (s *ArduinoCoreServerImpl) ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) {
resp, err := upload.ListProgrammersAvailableForUpload(ctx, req) resp, err := ListProgrammersAvailableForUpload(ctx, req)
return resp, convertErrorToRPCStatus(err) return resp, convertErrorToRPCStatus(err)
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications. // Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc. // To purchase a commercial license, send an email to license@arduino.cc.
package upload package commands
import ( import (
"context" "context"
...@@ -31,7 +31,6 @@ import ( ...@@ -31,7 +31,6 @@ import (
"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/internal/arduino/globals" "github.com/arduino/arduino-cli/internal/arduino/globals"
"github.com/arduino/arduino-cli/internal/arduino/sketch" "github.com/arduino/arduino-cli/internal/arduino/sketch"
"github.com/arduino/arduino-cli/internal/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper" paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap" properties "github.com/arduino/go-properties-orderedmap"
...@@ -40,8 +39,6 @@ import ( ...@@ -40,8 +39,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var tr = i18n.Tr
// SupportedUserFields returns a SupportedUserFieldsResponse containing all the UserFields supported // SupportedUserFields returns a SupportedUserFieldsResponse containing all the UserFields supported
// by the upload tools needed by the board using the protocol specified in SupportedUserFieldsRequest. // by the upload tools needed by the board using the protocol specified in SupportedUserFieldsRequest.
func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) { func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) {
...@@ -179,8 +176,8 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er ...@@ -179,8 +176,8 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
}, nil }, nil
} }
// UsingProgrammer FIXMEDOC // UploadUsingProgrammer FIXMEDOC
func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest, outStream io.Writer, errStream io.Writer) error { func UploadUsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest, outStream io.Writer, errStream io.Writer) error {
logrus.Tracef("Upload using programmer %s on %s started", req.GetSketchPath(), req.GetFqbn()) logrus.Tracef("Upload using programmer %s on %s started", req.GetSketchPath(), req.GetFqbn())
if req.GetProgrammer() == "" { if req.GetProgrammer() == "" {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications. // Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc. // To purchase a commercial license, send an email to license@arduino.cc.
package upload package commands
import ( import (
"context" "context"
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications. // Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc. // To purchase a commercial license, send an email to license@arduino.cc.
package upload package commands
import ( import (
"context" "context"
......
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
"context" "context"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/internal/cli/instance" "github.com/arduino/arduino-cli/internal/cli/instance"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
) )
...@@ -58,7 +57,7 @@ func GetInstalledProgrammers() []string { ...@@ -58,7 +57,7 @@ func GetInstalledProgrammers() []string {
installedProgrammers := make(map[string]string) installedProgrammers := make(map[string]string)
for _, board := range list.GetBoards() { for _, board := range list.GetBoards() {
programmers, _ := upload.ListProgrammersAvailableForUpload(context.Background(), &rpc.ListProgrammersAvailableForUploadRequest{ programmers, _ := commands.ListProgrammersAvailableForUpload(context.Background(), &rpc.ListProgrammersAvailableForUploadRequest{
Instance: inst, Instance: inst,
Fqbn: board.GetFqbn(), Fqbn: board.GetFqbn(),
}) })
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
"errors" "errors"
"os" "os"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/internal/cli/arguments" "github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/internal/cli/instance" "github.com/arduino/arduino-cli/internal/cli/instance"
...@@ -75,7 +75,7 @@ func runBootloaderCommand(command *cobra.Command, args []string) { ...@@ -75,7 +75,7 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
} }
stdOut, stdErr, res := feedback.OutputStreams() stdOut, stdErr, res := feedback.OutputStreams()
if _, err := upload.BurnBootloader(context.Background(), &rpc.BurnBootloaderRequest{ if _, err := commands.BurnBootloader(context.Background(), &rpc.BurnBootloaderRequest{
Instance: instance, Instance: instance,
Fqbn: fqbn.String(), Fqbn: fqbn.String(),
Port: discoveryPort, Port: discoveryPort,
......
...@@ -27,7 +27,6 @@ import ( ...@@ -27,7 +27,6 @@ import (
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/sketch" "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/internal/cli/arguments" "github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/configuration" "github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
...@@ -249,7 +248,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -249,7 +248,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
var uploadRes *rpc.UploadResult var uploadRes *rpc.UploadResult
if compileError == nil && uploadAfterCompile { if compileError == nil && uploadAfterCompile {
userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{ userFieldRes, err := commands.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
Instance: inst, Instance: inst,
Fqbn: fqbn, Fqbn: fqbn,
Protocol: port.GetProtocol(), Protocol: port.GetProtocol(),
...@@ -288,7 +287,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -288,7 +287,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
UserFields: fields, UserFields: fields,
} }
if res, err := upload.Upload(context.Background(), uploadRequest, stdOut, stdErr); err != nil { if res, err := commands.Upload(context.Background(), uploadRequest, stdOut, stdErr); err != nil {
errcode := feedback.ErrGeneric errcode := feedback.ErrGeneric
if errors.Is(err, &cmderrors.ProgrammerRequiredForUploadError{}) { if errors.Is(err, &cmderrors.ProgrammerRequiredForUploadError{}) {
errcode = feedback.ErrMissingProgrammer errcode = feedback.ErrMissingProgrammer
......
...@@ -25,7 +25,6 @@ import ( ...@@ -25,7 +25,6 @@ import (
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/commands/cmderrors"
sk "github.com/arduino/arduino-cli/commands/sketch" sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/internal/cli/arguments" "github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/feedback" "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/result"
...@@ -117,7 +116,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { ...@@ -117,7 +116,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
defaultProtocol := sketch.GetDefaultProtocol() defaultProtocol := sketch.GetDefaultProtocol()
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, defaultFQBN, defaultAddress, defaultProtocol) fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, defaultFQBN, defaultAddress, defaultProtocol)
userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{ userFieldRes, err := commands.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
Instance: inst, Instance: inst,
Fqbn: fqbn, Fqbn: fqbn,
Protocol: port.GetProtocol(), Protocol: port.GetProtocol(),
...@@ -198,7 +197,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { ...@@ -198,7 +197,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
DryRun: dryRun, DryRun: dryRun,
UserFields: fields, UserFields: fields,
} }
if res, err := upload.Upload(context.Background(), req, stdOut, stdErr); err != nil { if res, err := commands.Upload(context.Background(), req, stdOut, stdErr); err != nil {
errcode := feedback.ErrGeneric errcode := feedback.ErrGeneric
if errors.Is(err, &cmderrors.ProgrammerRequiredForUploadError{}) { if errors.Is(err, &cmderrors.ProgrammerRequiredForUploadError{}) {
errcode = feedback.ErrMissingProgrammer errcode = feedback.ErrMissingProgrammer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment