Skip to content

Commit

Permalink
fix: updated Makefile default; aligned all help texts; misc
Browse files Browse the repository at this point in the history
  • Loading branch information
trietsch committed Jul 12, 2021
1 parent 164dbb5 commit 175f23b
Show file tree
Hide file tree
Showing 18 changed files with 715 additions and 67 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY: build clean
.PHONY: build clean all
.DEFAULT_GOAL := all

SHELL := /bin/bash

Expand All @@ -10,10 +11,17 @@ zsh-completion:

# for a speedier build than with goreleaser
source_files := $(shell find . -name "*.go")

targetVar := streammachine.io/strm/cmd.CommandName

target := dstrm

ldflags := -X '${targetVar}=${target}'

${target}: ${source_files} Makefile
go build -ldflags="${ldflags}" -o $@

clean:
rm -f ${target}

all: ${target}
6 changes: 3 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"os"
)

var CommandName string
var RootCommandName string
var TokenFile string

const (
Expand All @@ -36,9 +36,9 @@ func login(apiHost string, s *string, cmd *cobra.Command) {
authClient := &Auth{Uri: apiHost}
authClient.AuthenticateLogin(s, &password)
_, billingId := authClient.GetToken(false)
fmt.Println("billingId", billingId)
fmt.Println("Billing id:", billingId)
filename := authClient.StoreLogin()
fmt.Println("saved login to", filename)
fmt.Println("Saved login to:", filename)
}

func askPassword() string {
Expand Down
5 changes: 3 additions & 2 deletions auth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func LoginCmd() *cobra.Command {
func PrintTokenCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "access-token",
Short: "print an access-token to stdout",
Short: "Print your current access-token to stdout",
Long: `Prints an access token that can be used in an http header.
Note that this token might be expired, so a refresh may be required.
Use token as follows:
'Authorization: Bearer <token>'
`,
Expand All @@ -38,7 +39,7 @@ func Refresh() *cobra.Command {
cmd := &cobra.Command{
Use: "refresh",
Short: "Refresh an existing access-token",
Long: `Not really necessary, the cli will auto-refresh.
Long: `Not really necessary, the CLI will auto-refresh.
`,
Run: func(cmd *cobra.Command, args []string) {
DoRefresh(apiHost(cmd))
Expand Down
8 changes: 4 additions & 4 deletions auth/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type token struct {
func (authorizer *Auth) GetToken(quiet bool) (string, string) {
if int64(authorizer.token.ExpiresAt)-30 < time.Now().Unix() {
if !quiet {
println("Refreshing sts token")
println("Refreshing STS token")
}
authorizer.refresh()
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func (authorizer *Auth) LoadLogin() {
filename := authorizer.getSaveFilename()
b, err := ioutil.ReadFile(filename)
if err != nil {
cobra.CheckErr(fmt.Sprintf("No login information found. Use: `%v auth login` first.", CommandName))
cobra.CheckErr(fmt.Sprintf("No login information found. Use: `%v auth login` first.", RootCommandName))
}
err = json.Unmarshal(b, &authorizer.token)
cobra.CheckErr(err)
Expand All @@ -149,6 +149,6 @@ func (authorizer *Auth) LoadLogin() {
func (authorizer *Auth) printToken() {
fmt.Println(authorizer.token.IdToken)
// these go to stderr, so the token is easy to capture in a script
println("Expires at", time.Unix(int64(authorizer.token.ExpiresAt), 0).String())
println("Billing-id", authorizer.token.BillingId)
println("Expires at:", time.Unix(int64(authorizer.token.ExpiresAt), 0).String())
println("Billing id:", authorizer.token.BillingId)
}
6 changes: 3 additions & 3 deletions cmd/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var EgressCmd = &cobra.Command{

func init() {
flags := EgressCmd.Flags()
flags.String(sims.ClientIdFlag, "", "client id to be used for sending data")
flags.String(sims.ClientSecretFlag, "", "client secret to be used for sending data")
flags.String(sims.ClientIdFlag, "", "Client id to be used for receiving data")
flags.String(sims.ClientSecretFlag, "", "Client secret to be used for receiving data")

}
}
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var RootCmd = &cobra.Command{
auth.ConfigPath = cfgPath
utils.ConfigPath = cfgPath

auth.CommandName = CommandName
auth.RootCommandName = CommandName

if cmd.Parent() != AuthCmd && cmd != CompletionCmd && cmd != VersionCmd && cmd.Name() != "help" {
apiAuthUrl := utils.GetStringAndErr(cmd.Flags(), auth.ApiAuthUrlFlag)
Expand Down Expand Up @@ -132,12 +132,12 @@ func init() {
cfgPath, err = utils.ExpandTilde("~/.config/stream-machine")
cobra.CheckErr(err)

RootCmd.PersistentFlags().String(apiHostFlag, "apis.streammachine.io:443", "api host and port")
RootCmd.PersistentFlags().String(apiHostFlag, "apis.streammachine.io:443", "API host and port")
RootCmd.PersistentFlags().String(auth.EventAuthHostFlag, "https://auth.strm.services", "Security Token Service for events")
RootCmd.PersistentFlags().String(auth.ApiAuthUrlFlag, "https://api.streammachine.io/v1", "Auth URL for user logins")
RootCmd.PersistentFlags().StringVar(&auth.TokenFile, "token-file", "",
"config file (default is $HOME/.config/stream-machine/strm-creds-<api-auth-host>.json)")
RootCmd.PersistentFlags().String(egress.UrlFlag, "wss://out.strm.services/ws", "where to retrieve the events")
"Token file that contains an access token (default is $HOME/.config/stream-machine/strm-creds-<api-auth-host>.json)")
RootCmd.PersistentFlags().String(egress.UrlFlag, "wss://out.strm.services/ws", "Websocket to receive events from")
setupVerbs()
}

Expand Down Expand Up @@ -207,4 +207,4 @@ func bindFlags(cmd *cobra.Command, v *viper.Viper) {
cobra.CheckErr(err)
}
})
}
}
6 changes: 3 additions & 3 deletions entity/batch_exporter/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
func DeleteCmd() *cobra.Command {
batchExporter := &cobra.Command{
Use: "batch-exporter [name]",
Short: "delete batch-exporter by name",
Short: "Delete a Batch exporter by name",
Run: func(cmd *cobra.Command, args []string) {
del(&args[0])
},
Expand All @@ -31,7 +31,7 @@ func DeleteCmd() *cobra.Command {
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "batch-exporter [name]",
Short: "get batch-exporter by name",
Short: "Get Batch exporter by name",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0], cmd)
},
Expand All @@ -42,7 +42,7 @@ func GetCmd() *cobra.Command {
func ListCmd() *cobra.Command {
return &cobra.Command{
Use: "batch-exporters",
Short: "List batch-exporters",
Short: "List Batch exporters",
Run: func(cmd *cobra.Command, args []string) {
list()
},
Expand Down
4 changes: 2 additions & 2 deletions entity/event_contract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/spf13/cobra"
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "event-contract [name]",
Short: "get event-contract by name",
Short: "Get Event Contract by name",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0])
},
Expand All @@ -16,7 +16,7 @@ func GetCmd() *cobra.Command {
func ListCmd() *cobra.Command {
return &cobra.Command{
Use: "event-contracts",
Short: "List event-contracts",
Short: "List Event Contracts",
Run: func(cmd *cobra.Command, args []string) {
list()
},
Expand Down
4 changes: 2 additions & 2 deletions entity/kafka_cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/spf13/cobra"
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-cluster [name]",
Short: "get kafka-cluster by name",
Short: "Get Kafka cluster by name",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0])
},
Expand All @@ -16,7 +16,7 @@ func GetCmd() *cobra.Command {
func ListCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-clusters",
Short: "List kafka-clusters",
Short: "List Kafka clusters",
Run: func(cmd *cobra.Command, args []string) {
list()
},
Expand Down
12 changes: 6 additions & 6 deletions entity/kafka_exporter/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const (
func DeleteCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-exporter [name]",
Short: "Delete a kafka-exporter",
Long: `Delete a kafka-exporter.
If a kafka-exporter has dependents (like kafka-users), you can use
Short: "Delete a Kafka exporter",
Long: `Delete a Kafka exporter.
If a kafka-exporter has dependents (like Kafka users), you can use
the 'recursive' option to get rid of those also.
Returns everything that was deleted. `,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -31,7 +31,7 @@ func DeleteCmd() *cobra.Command {
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-exporter [name]",
Short: "get kafka-exporter by name",
Short: "Get Kafka exporter by name",
Run: func(cmd *cobra.Command, args []string) {
recursive, _ := cmd.Flags().GetBool("recursive")
get(&args[0], recursive)
Expand All @@ -44,7 +44,7 @@ func GetCmd() *cobra.Command {
func ListCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-exporters",
Short: "List kafka-exporters",
Short: "List Kafka exporters",
Run: func(cmd *cobra.Command, args []string) {
flag, _ := cmd.Root().PersistentFlags().GetBool("recursive")
list(flag)
Expand All @@ -56,7 +56,7 @@ func CreateCmd() *cobra.Command {

kafkaExporter := &cobra.Command{
Use: "kafka-exporter [stream-name]",
Short: "create a kafka-exporter",
Short: "Create a Kafka exporter",
Run: func(cmd *cobra.Command, args []string) {
streamName := &args[0]
create(streamName, cmd)
Expand Down
8 changes: 4 additions & 4 deletions entity/kafka_user/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
func DeleteCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-user [name]",
Short: "Delete a kafka-user",
Short: "Delete a Kafka user",
Run: func(cmd *cobra.Command, args []string) {
del(&args[0])
},
Expand All @@ -25,7 +25,7 @@ func DeleteCmd() *cobra.Command {
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-user [name]",
Short: "get a kafka-user",
Short: "Get Kafka user",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0])
},
Expand All @@ -37,7 +37,7 @@ func GetCmd() *cobra.Command {
func ListCmd() *cobra.Command {
return &cobra.Command{
Use: "kafka-users [kafka-exporter-name]",
Short: "List kafka-users",
Short: "List Kafka users",
Run: func(cmd *cobra.Command, args []string) {
list(&args[0])
},
Expand All @@ -49,7 +49,7 @@ func ListCmd() *cobra.Command {
func CreateCmd() *cobra.Command {
kafkaUser := &cobra.Command{
Use: "kafka-user [exporter-name]",
Short: "create a kafka-user on a named kafka-exporter",
Short: "Create a Kafka user on a Kafka exporter",
Run: func(cmd *cobra.Command, args []string) {
streamName := &args[0]
create(streamName, cmd)
Expand Down
2 changes: 1 addition & 1 deletion entity/key_stream/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/spf13/cobra"
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "key-stream [name]",
Short: "get key-stream by name",
Short: "Get key stream by name",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0])
},
Expand Down
2 changes: 1 addition & 1 deletion entity/schema/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/spf13/cobra"
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "schema [name]",
Short: "get schema by name",
Short: "Get schema by name",
Run: func(cmd *cobra.Command, args []string) {
get(&args[0])
},
Expand Down
2 changes: 1 addition & 1 deletion entity/sink/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "sink [name]",
Short: "get sink by name",
Short: "Get sink by name",
Run: func(cmd *cobra.Command, args []string) {
recursive, _ := cmd.Flags().GetBool("recursive")
get(&args[0], recursive)
Expand Down
6 changes: 3 additions & 3 deletions entity/stream/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func CreateCmd() *cobra.Command {

stream := &cobra.Command{
Use: "stream [name]",
Short: "create a stream",
Short: "Create a stream",
Run: func(cmd *cobra.Command, args []string) {
create(args, cmd)

Expand Down Expand Up @@ -53,7 +53,7 @@ func DeleteCmd() *cobra.Command {
func GetCmd() *cobra.Command {
return &cobra.Command{
Use: "stream [name]",
Short: "A brief description of your command",
Short: "Get stream by name",
Run: func(cmd *cobra.Command, args []string) {
recursive, _ := cmd.Flags().GetBool("recursive")
get(&args[0], recursive)
Expand All @@ -71,4 +71,4 @@ func ListCmd() *cobra.Command {
list(recursive)
},
}
}
}
Loading

0 comments on commit 175f23b

Please sign in to comment.