1
1
package kafka
2
2
3
3
import (
4
- "errors"
5
4
"flag"
6
5
"fmt"
7
6
"os"
@@ -78,7 +77,7 @@ func ParseArgument() (*Argument, error) {
78
77
79
78
if len (os .Args ) < 2 {
80
79
argument .Help = flag .Usage
81
- return argument , errors . New ( "require at least one arguments" )
80
+ return argument , ErrorRequiredOneArgument
82
81
}
83
82
84
83
if ! strings .Contains (os .Args [1 ], "version" ) {
@@ -89,7 +88,7 @@ func ParseArgument() (*Argument, error) {
89
88
subscribeCommand .Parse (os .Args [2 :])
90
89
default :
91
90
argument .Help = flag .Usage
92
- return argument , errors . New ( "invalid command" )
91
+ return argument , ErrorInvalidCommand
93
92
}
94
93
}
95
94
@@ -98,25 +97,25 @@ func ParseArgument() (*Argument, error) {
98
97
99
98
if len (brokers ) <= 0 {
100
99
argument .Help = flag .Usage
101
- return argument , errors . New ( "require at least one broker" )
100
+ return argument , ErrorRequiredOneBroker
102
101
}
103
102
104
103
if len (topic ) <= 0 {
105
104
argument .Help = flag .Usage
106
- return argument , errors . New ( "require a topic name" )
105
+ return argument , ErrorRequiredTopicName
107
106
}
108
107
109
108
if len (message ) <= 0 {
110
109
argument .Help = flag .Usage
111
- return argument , errors . New ( "pub command require a message" )
110
+ return argument , ErrorPubRequredMessage
112
111
}
113
112
114
113
for _ , broker := range brokers {
115
114
if broker == "" {
116
115
continue
117
116
}
118
117
119
- argument .Brokers = append (argument .Brokers , broker )
118
+ argument .Brokers = append (argument .Brokers , strings . Trim ( broker , " " ) )
120
119
}
121
120
122
121
argument .Topic = topic
@@ -129,20 +128,20 @@ func ParseArgument() (*Argument, error) {
129
128
130
129
if len (brokers ) <= 0 {
131
130
argument .Help = flag .Usage
132
- return argument , errors . New ( "require at least one broker" )
131
+ return argument , ErrorRequiredOneBroker
133
132
}
134
133
135
134
if len (topic ) <= 0 {
136
135
argument .Help = flag .Usage
137
- return argument , errors . New ( "require a topic name" )
136
+ return argument , ErrorRequiredTopicName
138
137
}
139
138
140
139
for _ , broker := range brokers {
141
140
if broker == "" {
142
141
continue
143
142
}
144
143
145
- argument .Brokers = append (argument .Brokers , broker )
144
+ argument .Brokers = append (argument .Brokers , strings . Trim ( broker , " " ) )
146
145
}
147
146
148
147
argument .Topic = topic
0 commit comments