Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
},
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
16 changes: 10 additions & 6 deletions external/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=