Skip to content

Commit

Permalink
Add support for default profiles to upload command
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Aug 21, 2023
1 parent b3b36c6 commit bc49faf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,25 @@ func runUploadCommand(command *cobra.Command, args []string) {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
}

instance, profile := instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
var inst *rpc.Instance
var profile *rpc.Profile

if profileArg.Get() == "" {
inst, profile = instance.CreateAndInitWithProfile(sk.Project.DefaultProfile, sketchPath)
} else {
inst, profile = instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
}

if fqbnArg.String() == "" {
fqbnArg.Set(profile.GetFqbn())
}

defaultFQBN := sk.GetDefaultFQBN()
defaultAddress, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, defaultFQBN, defaultAddress, defaultProtocol)
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, defaultFQBN, defaultAddress, defaultProtocol)

userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
Instance: instance,
Instance: inst,
Fqbn: fqbn,
Protocol: port.Protocol,
})
Expand All @@ -122,7 +130,7 @@ func runUploadCommand(command *cobra.Command, args []string) {
}

// FIXME: Here we must not access package manager...
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: instance})
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
platform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: split[1],
Expand Down Expand Up @@ -156,7 +164,7 @@ func runUploadCommand(command *cobra.Command, args []string) {

stdOut, stdErr, stdIOResult := feedback.OutputStreams()
req := &rpc.UploadRequest{
Instance: instance,
Instance: inst,
Fqbn: fqbn,
SketchPath: path,
Port: port,
Expand Down

0 comments on commit bc49faf

Please sign in to comment.