package main import ( "fmt" "github.com/spf13/cobra" ) var cobraCmd = &cobra.Command{ Use: "eno", Short: "file encryption tool", } var encryptCmd = &cobra.Command{ Use: "encrypt ", 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 ", 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) }