Skip to content

Commit 4b36452

Browse files
committed
remove some code duplication
1 parent 225fbbd commit 4b36452

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
@@ -190,12 +190,12 @@ func run(cmd *cobra.Command, args []string) {
190190
}
191191

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

cli/firmware/flash.go

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

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

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)