Skip to content

Commit

Permalink
Merge pull request birdayz#43 from bdomars/cmdline-overrides
Browse files Browse the repository at this point in the history
cmd/kaf: Changed logic so cmdline always wins
  • Loading branch information
birdayz authored Mar 25, 2019
2 parents 7850103 + 95f60a6 commit ffd4fdc
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions cmd/kaf/kaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,26 @@ func onInit() {
panic(err)
}

// Flag is highest priority override
if brokersFlag != nil {
currentCluster = &kaf.Cluster{
Brokers: brokersFlag,
SchemaRegistryURL: schemaRegistryURL,
}
cluster := config.ActiveCluster()
if cluster != nil {
// Use active cluster from config
currentCluster = cluster
} else {
// If no override from flag is set, get current cluster from config file
if cluster := config.ActiveCluster(); cluster != nil {
currentCluster = cluster
} else {
// Default to localhost:9092 with no security
currentCluster = &kaf.Cluster{
Brokers: []string{"localhost:9092"},
SchemaRegistryURL: schemaRegistryURL,
}
// Create sane default if not configured
currentCluster = &kaf.Cluster{
Brokers: []string{"localhost:9092"},
}
}

// Any set flags override the configuration
if schemaRegistryURL != "" {
currentCluster.SchemaRegistryURL = schemaRegistryURL
}

if brokersFlag != nil {
currentCluster.Brokers = brokersFlag
}

}

func getClusterAdmin() (admin sarama.ClusterAdmin, err error) {
Expand Down

0 comments on commit ffd4fdc

Please sign in to comment.