Skip to content

Commit 8998580

Browse files
committed
replace error with custom error type
1 parent d395fca commit 8998580

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

args.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kafka
22

33
import (
4-
"errors"
54
"flag"
65
"fmt"
76
"os"
@@ -78,7 +77,7 @@ func ParseArgument() (*Argument, error) {
7877

7978
if len(os.Args) < 2 {
8079
argument.Help = flag.Usage
81-
return argument, errors.New("require at least one arguments")
80+
return argument, ErrorRequiredOneArgument
8281
}
8382

8483
if !strings.Contains(os.Args[1], "version") {
@@ -89,7 +88,7 @@ func ParseArgument() (*Argument, error) {
8988
subscribeCommand.Parse(os.Args[2:])
9089
default:
9190
argument.Help = flag.Usage
92-
return argument, errors.New("invalid command")
91+
return argument, ErrorInvalidCommand
9392
}
9493
}
9594

@@ -98,25 +97,25 @@ func ParseArgument() (*Argument, error) {
9897

9998
if len(brokers) <= 0 {
10099
argument.Help = flag.Usage
101-
return argument, errors.New("require at least one broker")
100+
return argument, ErrorRequiredOneBroker
102101
}
103102

104103
if len(topic) <= 0 {
105104
argument.Help = flag.Usage
106-
return argument, errors.New("require a topic name")
105+
return argument, ErrorRequiredTopicName
107106
}
108107

109108
if len(message) <= 0 {
110109
argument.Help = flag.Usage
111-
return argument, errors.New("pub command require a message")
110+
return argument, ErrorPubRequredMessage
112111
}
113112

114113
for _, broker := range brokers {
115114
if broker == "" {
116115
continue
117116
}
118117

119-
argument.Brokers = append(argument.Brokers, broker)
118+
argument.Brokers = append(argument.Brokers, strings.Trim(broker, " "))
120119
}
121120

122121
argument.Topic = topic
@@ -129,20 +128,20 @@ func ParseArgument() (*Argument, error) {
129128

130129
if len(brokers) <= 0 {
131130
argument.Help = flag.Usage
132-
return argument, errors.New("require at least one broker")
131+
return argument, ErrorRequiredOneBroker
133132
}
134133

135134
if len(topic) <= 0 {
136135
argument.Help = flag.Usage
137-
return argument, errors.New("require a topic name")
136+
return argument, ErrorRequiredTopicName
138137
}
139138

140139
for _, broker := range brokers {
141140
if broker == "" {
142141
continue
143142
}
144143

145-
argument.Brokers = append(argument.Brokers, broker)
144+
argument.Brokers = append(argument.Brokers, strings.Trim(broker, " "))
146145
}
147146

148147
argument.Topic = topic

0 commit comments

Comments
 (0)