summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/caddyauth
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2023-02-24 18:09:12 -0500
committerGitHub <noreply@github.com>2023-02-24 16:09:12 -0700
commit9e6919550be5689628d0020ec14e90ea6f527716 (patch)
tree81865f63e5ef549f8548cd6e22e9aa89d4eaf207 /modules/caddyhttp/caddyauth
parent167981d258f41b7ef931d510056a5a5fdc9cbd0d (diff)
cmd: Expand cobra support, add short flags (#5379)
* cmd: Expand cobra support * Convert commands to cobra, add short flags * Fix version command typo Co-authored-by: Emily Lange <git@indeednotjames.com> * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> --------- Co-authored-by: Emily Lange <git@indeednotjames.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddyhttp/caddyauth')
-rw-r--r--modules/caddyhttp/caddyauth/command.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/modules/caddyhttp/caddyauth/command.go b/modules/caddyhttp/caddyauth/command.go
index 609de4e..915bcd3 100644
--- a/modules/caddyhttp/caddyauth/command.go
+++ b/modules/caddyhttp/caddyauth/command.go
@@ -18,20 +18,19 @@ import (
"bufio"
"bytes"
"encoding/base64"
- "flag"
"fmt"
"os"
"os/signal"
"github.com/caddyserver/caddy/v2"
caddycmd "github.com/caddyserver/caddy/v2/cmd"
+ "github.com/spf13/cobra"
"golang.org/x/term"
)
func init() {
caddycmd.RegisterCommand(caddycmd.Command{
Name: "hash-password",
- Func: cmdHashPassword,
Usage: "[--algorithm <name>] [--salt <string>] [--plaintext <password>]",
Short: "Hashes a password and writes base64",
Long: `
@@ -50,13 +49,12 @@ be provided (scrypt).
Note that scrypt is deprecated. Please use 'bcrypt' instead.
`,
- Flags: func() *flag.FlagSet {
- fs := flag.NewFlagSet("hash-password", flag.ExitOnError)
- fs.String("algorithm", "bcrypt", "Name of the hash algorithm")
- fs.String("plaintext", "", "The plaintext password")
- fs.String("salt", "", "The password salt")
- return fs
- }(),
+ CobraFunc: func(cmd *cobra.Command) {
+ cmd.Flags().StringP("plaintext", "p", "", "The plaintext password")
+ cmd.Flags().StringP("salt", "s", "", "The password salt")
+ cmd.Flags().StringP("algorithm", "a", "bcrypt", "Name of the hash algorithm")
+ cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdHashPassword)
+ },
})
}