From 976643566aa21b08283e391f5e16b00c5aec40e0 Mon Sep 17 00:00:00 2001 From: Bart van Deenen Date: Fri, 9 Jul 2021 13:43:12 +0200 Subject: [PATCH] feat(config-path): config path used for saving --- Makefile | 8 +++++++- cmd/root.go | 3 ++- utils/utils.go | 9 ++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index cfc9d3f..7280e38 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build +.PHONY: build clean SHELL := /bin/bash @@ -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 diff --git a/cmd/root.go b/cmd/root.go index c63d33e..1418ac8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) @@ -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", "", diff --git a/utils/utils.go b/utils/utils.go index 4c304cf..c6478ab 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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" @@ -14,6 +13,8 @@ import ( "strconv" ) +var ConfigPath string + func Print(m proto.Message) { marshal, _ := protojson.Marshal(m) fmt.Println(string(marshal)) @@ -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") +} \ No newline at end of file