Skip to content

Commit b31c26a

Browse files
committed
remove some code duplication
1 parent 00eadcc commit b31c26a

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

195195
// Print the results
196-
feedback.PrintResult(&flashResult{
197-
Programmer: (&ExecOutput{
196+
feedback.PrintResult(&flasher.FlashResult{
197+
Programmer: (&flasher.ExecOutput{
198198
Stdout: programmerOut.String(),
199199
Stderr: programmerErr.String(),
200200
}),
201-
Flasher: (&ExecOutput{
201+
Flasher: (&flasher.ExecOutput{
202202
Stdout: flasherOut.String(),
203203
Stderr: flasherErr.String(),
204204
}),
@@ -208,22 +208,3 @@ func run(cmd *cobra.Command, args []string) {
208208
os.Exit(errorcodes.ErrGeneric)
209209
}
210210
}
211-
212-
type flashResult struct {
213-
Programmer *ExecOutput `json:"programmer"`
214-
Flasher *ExecOutput `json:"flasher"`
215-
}
216-
217-
type ExecOutput struct {
218-
Stdout string `json:"stdout"`
219-
Stderr string `json:"stderr"`
220-
}
221-
222-
func (r *flashResult) Data() interface{} {
223-
return r
224-
}
225-
226-
func (r *flashResult) String() string {
227-
// The output is already printed via os.Stdout/os.Stdin
228-
return ""
229-
}

cli/firmware/flash.go

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

220220
// Print the results
221-
feedback.PrintResult(&flashResult{
222-
Programmer: (&ExecOutput{
221+
feedback.PrintResult(&flasher.FlashResult{
222+
Programmer: (&flasher.ExecOutput{
223223
Stdout: programmerOut.String(),
224224
Stderr: programmerErr.String(),
225225
}),
226-
Flasher: (&ExecOutput{
226+
Flasher: (&flasher.ExecOutput{
227227
Stdout: flasherOut.String(),
228228
Stderr: flasherErr.String(),
229229
}),
@@ -233,22 +233,3 @@ func run(cmd *cobra.Command, args []string) {
233233
os.Exit(errorcodes.ErrGeneric)
234234
}
235235
}
236-
237-
type flashResult struct {
238-
Programmer *ExecOutput `json:"programmer"`
239-
Flasher *ExecOutput `json:"flasher"`
240-
}
241-
242-
type ExecOutput struct {
243-
Stdout string `json:"stdout"`
244-
Stderr string `json:"stderr"`
245-
}
246-
247-
func (r *flashResult) Data() interface{} {
248-
return r
249-
}
250-
251-
func (r *flashResult) String() string {
252-
// The output is already printed via os.Stdout/os.Stdin
253-
return ""
254-
}

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)