-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
662 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Binary | ||
kafkactl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
// Copyright © 2018 NAME HERE <EMAIL ADDRESS> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ConfigCmd represents the config command | ||
var ConfigCmd = &cobra.Command{ | ||
var CmdConfig = &cobra.Command{ | ||
Use: "config", | ||
Short: "show and edit configurations", | ||
} | ||
|
||
func init() { | ||
ConfigCmd.AddCommand(currentContextCmd) | ||
ConfigCmd.AddCommand(getContextsCmd) | ||
ConfigCmd.AddCommand(useContextCmd) | ||
CmdConfig.AddCommand(cmdCurrentContext) | ||
CmdConfig.AddCommand(cmdGetContexts) | ||
CmdConfig.AddCommand(cmdUseContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
// Copyright © 2018 NAME HERE <EMAIL ADDRESS> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/deviceinsight/kafkactl/output" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// getContextsCmd represents the getContexts command | ||
var getContextsCmd = &cobra.Command{ | ||
var outputFormat string | ||
|
||
var cmdGetContexts = &cobra.Command{ | ||
Use: "get-contexts", | ||
Aliases: []string{"getContexts"}, | ||
Short: "list configured contexts", | ||
Long: `Output names of all configured contexts`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
contexts := viper.GetStringMap("contexts") | ||
for name := range contexts { | ||
fmt.Println(name) | ||
currentContext := viper.GetString("current-context") | ||
|
||
if outputFormat == "compact" { | ||
for name := range contexts { | ||
fmt.Println(name) | ||
} | ||
} else { | ||
writer := output.CreateTableWriter() | ||
|
||
writer.WriteHeader("ACTIVE", "NAME") | ||
for context := range contexts { | ||
if currentContext == context { | ||
writer.Write("*", context) | ||
} else { | ||
writer.Write("", context) | ||
} | ||
} | ||
|
||
writer.Flush() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
cmdGetContexts.Flags().StringVarP(&outputFormat, "output", "o", outputFormat, "Output format. One of: compact") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,25 @@ | ||
// Copyright © 2018 NAME HERE <EMAIL ADDRESS> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package consume | ||
|
||
import ( | ||
consumerTools "github.com/random-dwi/kafkactl/kafka/consumer" | ||
"github.com/random-dwi/kafkactl/util" | ||
"github.com/random-dwi/kafkactl/util/output" | ||
"github.com/deviceinsight/kafkactl/operations" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var flags consumerTools.ConsumerFlags | ||
var flags operations.ConsumerFlags | ||
|
||
// ConsumeCmd represents the consume command | ||
var ConsumeCmd = &cobra.Command{ | ||
var CmdConsume = &cobra.Command{ | ||
Use: "consume", | ||
Short: "consume messages from a topic", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cobraCmd *cobra.Command, args []string) { | ||
|
||
context := util.CreateClientContext() | ||
|
||
var topic = args[0] | ||
|
||
consumerContext := consumerTools.CreateConsumerContext(&context, topic, flags) | ||
|
||
partitions := consumerContext.FindPartitions() | ||
if len(partitions) == 0 { | ||
output.Failf("Found no partitions to consume") | ||
} | ||
|
||
defer consumerContext.Close() | ||
|
||
consumerContext.Consume(partitions) | ||
(&operations.ConsumerOperation{}).Consume(args[0], flags) | ||
}, | ||
} | ||
|
||
func init() { | ||
|
||
ConsumeCmd.Flags().BoolVarP(&flags.PrintKeys, "print-keys", "k", false, "print message printKeys") | ||
ConsumeCmd.Flags().BoolVarP(&flags.PrintTimestamps, "print-timestamps", "t", false, "print message printTimestamps") | ||
ConsumeCmd.Flags().StringVarP(&flags.ConsumerGroup, "consumer-group", "g", "", "consumer group to join") | ||
ConsumeCmd.Flags().StringArrayVarP(&flags.Offsets, "offset", "f", flags.Offsets, "define offsets for consumer") | ||
|
||
ConsumeCmd.Flags().StringVarP(&flags.OutputFormat, "output", "o", flags.OutputFormat, "Output format. One of: json|yaml") | ||
CmdConsume.Flags().BoolVarP(&flags.PrintKeys, "print-keys", "k", false, "print message printKeys") | ||
CmdConsume.Flags().BoolVarP(&flags.PrintTimestamps, "print-timestamps", "t", false, "print message printTimestamps") | ||
CmdConsume.Flags().StringVarP(&flags.ConsumerGroup, "consumer-group", "g", "", "consumer group to join") | ||
CmdConsume.Flags().StringArrayVarP(&flags.Offsets, "offset", "f", flags.Offsets, "define offsets for consumer") | ||
CmdConsume.Flags().StringVarP(&flags.OutputFormat, "output", "o", flags.OutputFormat, "Output format. One of: json|yaml") | ||
} |
Oops, something went wrong.