Skip to content

Commit 69b730c

Browse files
committed
v1.0.2
1 parent 10e79fa commit 69b730c

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: rpm clean source test
22

3-
KAFKA_OPS_VERSION ?= 1.0.1
3+
KAFKA_OPS_VERSION ?= 1.0.2
44
BUILD_NUMBER ?= 1
55
KAFKA_OPS ?= kafka-ops
66
REPO ?= github.com/agapoff/${KAFKA_OPS}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ Usage: ./kafka-ops <action> [<options>] [<broker connection options>]
232232
See also --json and --yaml options
233233
--apply Idempotently align cluster resources with the spec manifest
234234
See also --spec, --json and --yaml options
235+
--version Show version
235236
----------------
236237
Options
237238
--spec A path to manifest (specification file) to be used

main.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ import (
1616
"text/template"
1717
)
1818

19+
const version string = "1.0.2"
20+
1921
var (
20-
broker string
21-
specfile string
22-
protocol string
23-
mechanism string
24-
username string
25-
password string
26-
verbose bool
27-
isYAML bool
28-
isJSON bool
29-
actionApply bool
30-
actionDump bool
31-
actionHelp bool
32-
errorStop bool
33-
isTemplate bool
34-
missingOk bool
35-
varFlags arrFlags
22+
broker string
23+
specfile string
24+
protocol string
25+
mechanism string
26+
username string
27+
password string
28+
verbose bool
29+
isYAML bool
30+
isJSON bool
31+
actionApply bool
32+
actionDump bool
33+
actionHelp bool
34+
actionVersion bool
35+
errorStop bool
36+
isTemplate bool
37+
missingOk bool
38+
varFlags arrFlags
3639
)
3740

3841
type arrFlags []string
@@ -118,6 +121,8 @@ func main() {
118121
}
119122
} else if actionHelp {
120123
usage()
124+
} else if actionVersion {
125+
printVersion()
121126
}
122127
}
123128

@@ -764,6 +769,7 @@ func validateFlags() {
764769
flag.BoolVar(&actionApply, "apply", false, "Apply spec-file to the broker, create all entities that do not exist there; this is the default action")
765770
flag.BoolVar(&actionDump, "dump", false, "Dump broker entities in YAML (default) or JSON format to stdout or to a file if --spec option is defined")
766771
flag.BoolVar(&actionHelp, "help", false, "Print usage")
772+
flag.BoolVar(&actionVersion, "version", false, "Show version")
767773
flag.BoolVar(&isYAML, "yaml", false, "Spec-file is in YAML format (will try to detect format if none of --yaml or --json is set)")
768774
flag.BoolVar(&isJSON, "json", false, "Spec-file is in JSON format (will try to detect format if none of --yaml or --json is set)")
769775
flag.BoolVar(&errorStop, "stop-on-error", false, "Exit on first occurred error")
@@ -779,8 +785,8 @@ func validateFlags() {
779785
protocol = strings.ToLower(protocol)
780786
mechanism = strings.ToLower(mechanism)
781787

782-
if !actionApply && !actionDump && !actionHelp {
783-
fmt.Println("Please define one of the actions: --dump, --apply, --help")
788+
if !actionApply && !actionDump && !actionHelp && !actionVersion {
789+
fmt.Println("Please define one of the actions: --dump, --apply, --help, --version")
784790
os.Exit(1)
785791
}
786792
if actionApply && actionDump {
@@ -814,6 +820,11 @@ func validateFlags() {
814820
}
815821
}
816822

823+
func printVersion() error {
824+
fmt.Println(version)
825+
return nil
826+
}
827+
817828
func usage() {
818829
usage := `Manage Kafka cluster resources (topics and ACLs)
819830
Usage: %s <action> [<options>] [<broker connection options>]
@@ -824,6 +835,7 @@ Usage: %s <action> [<options>] [<broker connection options>]
824835
See also --json and --yaml options
825836
--apply Idempotently align cluster resources with the spec manifest
826837
See also --spec, --json and --yaml options
838+
--version Show version
827839
----------------
828840
Options
829841
--spec A path to manifest (specification file) to be used

main_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io/ioutil"
1111
"log"
1212
"os"
13+
"regexp"
1314
"strings"
1415
"sync"
1516
)
@@ -223,9 +224,9 @@ func TestApplySpecFileDeleteAcl(t *testing.T) {
223224
defer seedBroker.Close()
224225

225226
seedBroker.SetHandlerByMap(map[string]sarama.MockResponse{
226-
// "SaslAuthenticateRequest": sarama.NewMockSaslAuthenticateResponse(t),
227-
// "SaslHandshakeRequest": sarama.NewMockSaslHandshakeResponse(t).
228-
// SetEnabledMechanisms([]string{sarama.SASLTypeSCRAMSHA256, sarama.SASLTypeSCRAMSHA512}),
227+
//"SaslAuthenticateRequest": sarama.NewMockSaslAuthenticateResponse(t),
228+
//"SaslHandshakeRequest": sarama.NewMockSaslHandshakeResponse(t).
229+
// SetEnabledMechanisms([]string{sarama.SASLTypeSCRAMSHA256, sarama.SASLTypeSCRAMSHA512}),
229230
"MetadataRequest": sarama.NewMockMetadataResponse(t).
230231
SetController(seedBroker.BrokerID()).
231232
SetBroker(seedBroker.Addr(), seedBroker.BrokerID()),
@@ -268,3 +269,20 @@ func TestGetHost(t *testing.T) {
268269
t.Errorf("getHost failed, expected %s, got %s", "*", host)
269270
}
270271
}
272+
273+
func TestVersion(t *testing.T) {
274+
out, _ := captureOutput(func() error { return printVersion() })
275+
trimOut := strings.TrimSuffix(out, "\n")
276+
277+
re := regexp.MustCompile(`KAFKA_OPS_VERSION\s*\??=\s*(.+)`)
278+
makefile, err := ioutil.ReadFile("Makefile")
279+
280+
if err != nil {
281+
t.Fatal("Failed to read Makefile: " + err.Error())
282+
}
283+
v := re.FindAllSubmatch(makefile, -1)
284+
expected := string(v[0][1])
285+
if trimOut != expected {
286+
t.Fatalf("Version output %s does not match the expected %s", trimOut, expected)
287+
}
288+
}

0 commit comments

Comments
 (0)