aboutsummaryrefslogtreecommitdiff
path: root/cmd/eno/cobra.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/eno/cobra.go')
-rw-r--r--cmd/eno/cobra.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go
new file mode 100644
index 0000000..1199aa0
--- /dev/null
+++ b/cmd/eno/cobra.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/spf13/cobra"
+)
+
+var cobraCmd = &cobra.Command{
+ Use: "eno",
+ Short: "file encryption tool",
+}
+
+var encryptCmd = &cobra.Command{
+ Use: "encrypt <file>",
+ Short: "encrypt a file",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ output, _ := cmd.Flags().GetString("output")
+ if output == "" {
+ return fmt.Errorf("output file required (-o)")
+ }
+ rawEncryptFile(args[0], output)
+ return nil
+ },
+}
+
+var decryptCmd = &cobra.Command{
+ Use: "decrypt <file>",
+ Short: "decrypt a file",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ output, _ := cmd.Flags().GetString("output")
+ if output == "" {
+ return fmt.Errorf("output file required (-o)")
+ }
+ rawDecryptFile(args[0], output)
+ return nil
+ },
+}
+
+func init() {
+ encryptCmd.Flags().StringP("output", "o", "", "output file (required)")
+ encryptCmd.MarkFlagRequired("output")
+
+ decryptCmd.Flags().StringP("output", "o", "", "output file (required)")
+ decryptCmd.MarkFlagRequired("output")
+
+ cobraCmd.AddCommand(encryptCmd, decryptCmd)
+}