From d32625467a9169874548c68aabd1f962d55f3cf1 Mon Sep 17 00:00:00 2001 From: Mahsa ghoreishi Date: Mon, 11 Apr 2022 15:21:07 -0400 Subject: [PATCH] issue_102 --- cmd/aliases.go | 12 ++++++++++++ cmd/root.go | 2 +- external/profiles/profiles.go | 16 ++++++++++------ go.sum | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/aliases.go b/cmd/aliases.go index b04a277b..959ceb19 100644 --- a/cmd/aliases.go +++ b/cmd/aliases.go @@ -4,8 +4,10 @@ import ( "fmt" "github.com/elasticpath/epcc-cli/external/aliases" "github.com/elasticpath/epcc-cli/external/completion" + "github.com/elasticpath/epcc-cli/external/profiles" "github.com/elasticpath/epcc-cli/external/resources" "github.com/spf13/cobra" + "os" "sort" ) @@ -54,3 +56,13 @@ var aliasListCmd = &cobra.Command{ return []string{}, cobra.ShellCompDirectiveNoFileComp }, } + +var aliasClearCmd = &cobra.Command{ + Use: "clear", + Short: "clear all aliases", + RunE: func(cmd *cobra.Command, args []string) error { + profileDirectory := profiles.GetProfileDataBaseURL() + os.RemoveAll(profileDirectory) + return nil + }, +} diff --git a/cmd/root.go b/cmd/root.go index 0db4367d..cec9c5c7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -46,7 +46,7 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&json.MonochromeOutput, "monochrome-output", "M", false, "By default, epcc will output using colors if the terminal supports this. Use this option to disable it.") rootCmd.PersistentFlags().StringSliceVarP(&globals.RawHeaders, "header", "H", []string{}, "Extra headers and values to include in the request when sending HTTP to a server. You may specify any number of extra headers.") - aliasesCmd.AddCommand(aliasListCmd) + aliasesCmd.AddCommand(aliasListCmd, aliasClearCmd) } var rootCmd = &cobra.Command{ diff --git a/external/profiles/profiles.go b/external/profiles/profiles.go index c5e21088..19c75a6a 100644 --- a/external/profiles/profiles.go +++ b/external/profiles/profiles.go @@ -31,12 +31,7 @@ func GetProfileName() string { } func GetProfileDirectory() string { - homeDir, err := os.UserHomeDir() - - if err != nil { - panic(fmt.Sprintf("Could not get user hoem directory home directory %v", err)) - } - profileDir := homeDir + "/.epcc/profiles_data/" + GetProfileName() + profileDir := GetProfileDataBaseURL() + GetProfileName() log.Tracef("Creating profile directory %s", profileDir) if err := os.MkdirAll(profileDir, 0700); err != nil { @@ -46,6 +41,15 @@ func GetProfileDirectory() string { return profileDir } +func GetProfileDataBaseURL() string { + homeDir, err := os.UserHomeDir() + if err != nil { + panic(fmt.Sprintf("Could not get user hoem directory home directory %v", err)) + } + + return homeDir + "/.epcc/profiles_data/" +} + // NewSHA256 ... func newSHA256(data []byte) []byte { hash := sha256.Sum256(data) diff --git a/go.sum b/go.sum index 04a5cdd0..6094db1e 100644 --- a/go.sum +++ b/go.sum @@ -1028,4 +1028,4 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= \ No newline at end of file