Skip to content

Commit 832a945

Browse files
committed
remove some code duplication
1 parent a3e9d70 commit 832a945

File tree

3 files changed

+25
-44
lines changed

3 files changed

+25
-44
lines changed

cli/certificates/flash.go

+3-22
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ func run(cmd *cobra.Command, args []string) {
189189
}
190190

191191
// Print the results
192-
feedback.PrintResult(&flashResult{
193-
Programmer: (&ExecOutput{
192+
feedback.PrintResult(&flasher.FlashResult{
193+
Programmer: (&flasher.ExecOutput{
194194
Stdout: programmerOut.String(),
195195
Stderr: programmerErr.String(),
196196
}),
197-
Flasher: (&ExecOutput{
197+
Flasher: (&flasher.ExecOutput{
198198
Stdout: flasherOut.String(),
199199
Stderr: flasherErr.String(),
200200
}),
@@ -204,22 +204,3 @@ func run(cmd *cobra.Command, args []string) {
204204
os.Exit(errorcodes.ErrGeneric)
205205
}
206206
}
207-
208-
type flashResult struct {
209-
Programmer *ExecOutput `json:"programmer"`
210-
Flasher *ExecOutput `json:"flasher"`
211-
}
212-
213-
type ExecOutput struct {
214-
Stdout string `json:"stdout"`
215-
Stderr string `json:"stderr"`
216-
}
217-
218-
func (r *flashResult) Data() interface{} {
219-
return r
220-
}
221-
222-
func (r *flashResult) String() string {
223-
// The output is already printed via os.Stdout/os.Stdin
224-
return ""
225-
}

cli/firmware/flash.go

+3-22
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ func run(cmd *cobra.Command, args []string) {
215215
}
216216

217217
// Print the results
218-
feedback.PrintResult(&flashResult{
219-
Programmer: (&ExecOutput{
218+
feedback.PrintResult(&flasher.FlashResult{
219+
Programmer: (&flasher.ExecOutput{
220220
Stdout: programmerOut.String(),
221221
Stderr: programmerErr.String(),
222222
}),
223-
Flasher: (&ExecOutput{
223+
Flasher: (&flasher.ExecOutput{
224224
Stdout: flasherOut.String(),
225225
Stderr: flasherErr.String(),
226226
}),
@@ -230,22 +230,3 @@ func run(cmd *cobra.Command, args []string) {
230230
os.Exit(errorcodes.ErrGeneric)
231231
}
232232
}
233-
234-
type flashResult struct {
235-
Programmer *ExecOutput `json:"programmer"`
236-
Flasher *ExecOutput `json:"flasher"`
237-
}
238-
239-
type ExecOutput struct {
240-
Stdout string `json:"stdout"`
241-
Stderr string `json:"stderr"`
242-
}
243-
244-
func (r *flashResult) Data() interface{} {
245-
return r
246-
}
247-
248-
func (r *flashResult) String() string {
249-
// The output is already printed via os.Stdout/os.Stdin
250-
return ""
251-
}

flasher/flasher.go

+19
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,22 @@ func openSerial(portAddress string) (serial.Port, error) {
9393

9494
return nil, lastError
9595
}
96+
97+
type FlashResult struct {
98+
Programmer *ExecOutput `json:"programmer"`
99+
Flasher *ExecOutput `json:"flasher"`
100+
}
101+
102+
type ExecOutput struct {
103+
Stdout string `json:"stdout"`
104+
Stderr string `json:"stderr"`
105+
}
106+
107+
func (r *FlashResult) Data() interface{} {
108+
return r
109+
}
110+
111+
func (r *FlashResult) String() string {
112+
// The output is already printed via os.Stdout/os.Stdin
113+
return ""
114+
}

0 commit comments

Comments
 (0)