Skip to content

Commit

Permalink
feat(config-path): config path used for saving
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdeenen committed Jul 9, 2021
1 parent f37f21e commit 9766435
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build
.PHONY: build clean

SHELL := /bin/bash

Expand All @@ -8,3 +8,9 @@ build:
zsh-completion:
/bin/zsh -c 'strm completion zsh > "$${fpath[1]}/_strm"'

# for a speedier build than with goreleaser
source_files := $(shell find . -name "*.go")
strm: ${source_files} Makefile
go build -o $@
clean:
rm -f strm
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var RootCmd = &cobra.Command{
apiHost := utils.GetStringAndErr(cmd.Flags(), apiHostFlag)

clientConnection, ctx := entity.SetupGrpc(apiHost, token)
utils.ConfigPath = cfgPath
sims.SetBillingId(billingId)
egress.BillingId = billingId
setupServiceClients(clientConnection, ctx)
Expand Down Expand Up @@ -129,7 +130,7 @@ func init() {

RootCmd.PersistentFlags().StringVar(&cfgPath, "config-path", "",
"config path (default is $HOME/.config/stream-machine/)")
RootCmd.PersistentFlags().String(apiHostFlag, "apis.streammachine.io:443", "API host name")
RootCmd.PersistentFlags().String(apiHostFlag, "apis.dev.streammachine.io:443", "api host and port")
RootCmd.PersistentFlags().String(auth.EventAuthHostFlag, "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", "",
Expand Down
9 changes: 4 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"google.golang.org/protobuf/encoding/protojson"
Expand All @@ -14,6 +13,8 @@ import (
"strconv"
)

var ConfigPath string

func Print(m proto.Message) {
marshal, _ := protojson.Marshal(m)
fmt.Println(string(marshal))
Expand Down Expand Up @@ -116,7 +117,5 @@ func DeleteSaved(m proto.Message, name *string) {

func getSaveFilename(m proto.Message, name *string) string {
cat := fmt.Sprint(m.ProtoReflect().Descriptor().Name())
home, err := homedir.Dir()
cobra.CheckErr(err)
return path.Join(home, ".config", "stream-machine", cat, *name+".json")
}
return path.Join(ConfigPath, cat, *name+".json")
}

0 comments on commit 9766435

Please sign in to comment.