@@ -43,13 +43,11 @@ type Extra struct {
43
43
ParamsQuiet string `json:"params_quiet"`
44
44
}
45
45
46
- // Resolve replaces some symbols in the commandline with the appropriate values
46
+ // PartiallyResolve replaces some symbols in the commandline with the appropriate values
47
47
// it can return an error when looking a variable in the Locater
48
- func Resolve ( port , board , file , commandline string , extra Extra , t Locater ) (string , error ) {
48
+ func PartiallyResolve ( board , file , commandline string , extra Extra , t Locater ) (string , error ) {
49
49
commandline = strings .Replace (commandline , "{build.path}" , filepath .ToSlash (filepath .Dir (file )), - 1 )
50
50
commandline = strings .Replace (commandline , "{build.project_name}" , strings .TrimSuffix (filepath .Base (file ), filepath .Ext (filepath .Base (file ))), - 1 )
51
- commandline = strings .Replace (commandline , "{serial.port}" , port , - 1 )
52
- commandline = strings .Replace (commandline , "{serial.port.file}" , filepath .Base (port ), - 1 )
53
51
54
52
if extra .Verbose == true {
55
53
commandline = strings .Replace (commandline , "{upload.verbose}" , extra .ParamsVerbose , - 1 )
@@ -67,12 +65,20 @@ func Resolve(port, board, file, commandline string, extra Extra, t Locater) (str
67
65
if err != nil {
68
66
return "" , errors .Wrapf (err , "get location of %s" , element )
69
67
}
70
- commandline = strings .Replace (commandline , element , location , 1 )
68
+ if location != "" {
69
+ commandline = strings .Replace (commandline , element , location , 1 )
70
+ }
71
71
}
72
72
73
73
return commandline , nil
74
74
}
75
75
76
+ func fixupPort (port , commandline string ) string {
77
+ commandline = strings .Replace (commandline , "{serial.port}" , port , - 1 )
78
+ commandline = strings .Replace (commandline , "{serial.port.file}" , filepath .Base (port ), - 1 )
79
+ return commandline
80
+ }
81
+
76
82
// Network performs a network upload
77
83
func Network (port , board , file , commandline string , auth Auth , l Logger ) error {
78
84
Busy = true
@@ -85,6 +91,8 @@ func Network(port, board, file, commandline string, auth Auth, l Logger) error {
85
91
auth .Password = "arduino"
86
92
}
87
93
94
+ commandline = fixupPort (port , commandline )
95
+
88
96
// try with a form
89
97
err := form (port , board , file , auth , l )
90
98
if err != nil {
@@ -110,6 +118,8 @@ func Serial(port, commandline string, extra Extra, l Logger) error {
110
118
}
111
119
}
112
120
121
+ commandline = fixupPort (port , commandline )
122
+
113
123
z , err := shellwords .Parse (commandline )
114
124
if err != nil {
115
125
return errors .Wrapf (err , "Parse commandline" )
0 commit comments