forked from gophercises/secret
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb5a214
commit f2d5c79
Showing
5 changed files
with
85 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/gophercises/secret/cmd/cobra" | ||
|
||
func main() { | ||
cobra.RootCmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cobra | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gophercises/secret" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Gets a secret in your secret storage", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
v := secret.File(encodingKey, secretsPath()) | ||
key := args[0] | ||
value, err := v.Get(key) | ||
if err != nil { | ||
fmt.Println("no value set") | ||
return | ||
} | ||
fmt.Printf("%s = %s\n", key, value) | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(getCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cobra | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
homedir "github.com/mitchellh/go-homedir" | ||
) | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "secret", | ||
Short: "Secret is an API key and other secrets manager", | ||
} | ||
|
||
var encodingKey string | ||
|
||
func init() { | ||
RootCmd.PersistentFlags().StringVarP(&encodingKey, "key", "k", "", "the key to use when encoding and decoding secrets") | ||
} | ||
|
||
func secretsPath() string { | ||
home, _ := homedir.Dir() | ||
return filepath.Join(home, ".secrets") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cobra | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gophercises/secret" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var setCmd = &cobra.Command{ | ||
Use: "set", | ||
Short: "Sets a secret in your secret storage", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
v := secret.File(encodingKey, secretsPath()) | ||
key, value := args[0], args[1] | ||
err := v.Set(key, value) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println("Value set successfully!") | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(setCmd) | ||
} |
This file was deleted.
Oops, something went wrong.