Skip to content

Commit d03da10

Browse files
author
rsora
committed
Implement --input-file flag
1 parent 76b255f commit d03da10

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

cli/upload/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewCommand() *cobra.Command {
5555
uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
5656
uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0")
5757
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries to upload.")
58-
uploadCommand.Flags().StringVarP(&importDir, "input-file", "", "", "Binary file to upload.")
58+
uploadCommand.Flags().StringVarP(&importFile, "input-file", "", "", "Binary file to upload.")
5959
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
6060
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
6161
uploadCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.")

commands/upload/burnbootloader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderReq, outStream i
3737
err := runProgramAction(
3838
pm,
3939
nil, // sketch
40-
"", // importDir
40+
"", // importFile,
41+
"", // importFile
4142
req.GetFqbn(),
4243
req.GetPort(),
4344
req.GetProgrammer(),

commands/upload/upload.go

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
5656
err = runProgramAction(
5757
pm,
5858
sketch,
59+
req.GetImportFile(),
5960
req.GetImportDir(),
6061
req.GetFqbn(),
6162
req.GetPort(),
@@ -73,7 +74,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
7374
}
7475

7576
func runProgramAction(pm *packagemanager.PackageManager,
76-
sketch *sketches.Sketch, importDir string, fqbnIn string, port string,
77+
sketch *sketches.Sketch, importFile string, importDir string, fqbnIn string, port string,
7778
programmerID string,
7879
verbose, verify, burnBootloader bool,
7980
outStream io.Writer, errStream io.Writer) error {
@@ -237,28 +238,37 @@ func runProgramAction(pm *packagemanager.PackageManager,
237238

238239
var importPath *paths.Path
239240
if !burnBootloader {
240-
if sketch == nil {
241-
return fmt.Errorf(("no sketch specified"))
242-
}
243-
244-
if importDir != "" {
245-
importPath = paths.New(importDir)
241+
if importFile != "" {
242+
importFilePath := paths.New(importFile)
243+
importFilePath.ToAbs()
244+
importPath = importFilePath.Parent()
245+
uploadProperties.SetPath("build.path", importPath)
246+
uploadProperties.Set("build.project_name", importFilePath.Base())
247+
feedback.Printf("build.path %s", importPath.String())
248+
feedback.Printf("build.project_name %s", importFilePath.Base())
246249
} else {
247-
// TODO: Create a function to obtain importPath from sketch
248-
importPath = sketch.FullPath
249-
// Add FQBN (without configs part) to export path
250-
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
251-
importPath = importPath.Join("build").Join(fqbnSuffix)
252-
}
250+
if sketch == nil {
251+
return fmt.Errorf(("no sketch specified"))
252+
}
253+
if importDir != "" {
254+
importPath = paths.New(importDir)
255+
} else {
256+
// TODO: Create a function to obtain importPath from sketch
257+
importPath = sketch.FullPath
258+
// Add FQBN (without configs part) to export path
259+
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
260+
importPath = importPath.Join("build").Join(fqbnSuffix)
261+
}
253262

254-
if !importPath.Exist() {
255-
return fmt.Errorf("compiled sketch not found in %s", importPath)
256-
}
257-
if !importPath.IsDir() {
258-
return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath)
263+
if !importPath.Exist() {
264+
return fmt.Errorf("compiled sketch not found in %s", importPath)
265+
}
266+
if !importPath.IsDir() {
267+
return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath)
268+
}
269+
uploadProperties.SetPath("build.path", importPath)
270+
uploadProperties.Set("build.project_name", sketch.Name+".ino")
259271
}
260-
uploadProperties.SetPath("build.path", importPath)
261-
uploadProperties.Set("build.project_name", sketch.Name+".ino")
262272
}
263273

264274
// If not using programmer perform some action required

0 commit comments

Comments
 (0)