Skip to content

Commit aefb91c

Browse files
committed
Code refactoring
1 parent 0ceb632 commit aefb91c

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

cli/ota/encode.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
)
3232

3333
type encodeBinaryFlags struct {
34-
deviceID string
35-
file string
34+
FQBN string
35+
file string
3636
}
3737

3838
func initEncodeBinaryCommand() *cobra.Command {
@@ -48,7 +48,7 @@ func initEncodeBinaryCommand() *cobra.Command {
4848
}
4949
},
5050
}
51-
uploadCommand.Flags().StringVarP(&flags.deviceID, "device-id", "d", "", "Device ID")
51+
uploadCommand.Flags().StringVarP(&flags.FQBN, "fqbn", "b", "", "Device fqbn")
5252
uploadCommand.Flags().StringVarP(&flags.file, "file", "", "", "Binary file (.bin) to be encoded")
5353
uploadCommand.MarkFlagRequired("device-id")
5454
uploadCommand.MarkFlagRequired("file")
@@ -64,8 +64,8 @@ func runEncodeCommand(flags *encodeBinaryFlags) error {
6464
}
6565

6666
params := &ota.EncodeParams{
67-
DeviceID: flags.deviceID,
68-
File: flags.file,
67+
FQBN: flags.FQBN,
68+
File: flags.file,
6969
}
7070
otafile, err := ota.Encode(context.TODO(), params, cred)
7171
if err != nil {

command/ota/encode.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,25 @@ import (
2323
"os"
2424

2525
"github.com/arduino/arduino-cloud-cli/config"
26-
"github.com/arduino/arduino-cloud-cli/internal/iot"
2726
)
2827

2928
type EncodeParams struct {
30-
DeviceID string
29+
FQBN string
3130
File string
3231
}
3332

3433
// Encode command is used to encode a firmware OTA
3534
func Encode(ctx context.Context, params *EncodeParams, cred *config.Credentials) (*string, error) {
36-
iotClient, err := iot.NewClient(cred)
37-
if err != nil {
38-
return nil, err
39-
}
40-
41-
dev, err := iotClient.DeviceShow(ctx, params.DeviceID)
42-
if err != nil {
43-
return nil, err
44-
}
45-
4635
otaFile := fmt.Sprintf("%s.ota", params.File)
47-
_, err = os.Stat(otaFile)
36+
_, err := os.Stat(otaFile)
4837
if err == nil {
4938
// file already exists, we need to delete it
5039
if err = os.Remove(otaFile); err != nil {
5140
return nil, fmt.Errorf("%s: %w", "cannot remove .ota file", err)
5241
}
5342
}
5443

55-
err = Generate(params.File, otaFile, dev.Fqbn)
44+
err = Generate(params.File, otaFile, params.FQBN)
5645
if err != nil {
5746
return nil, fmt.Errorf("%s: %w", "cannot generate .ota file", err)
5847
}

0 commit comments

Comments
 (0)