Peter Kurfer
9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
- setup ent scheme - add command to create users - document API - add helpers to create migrations - add command to run migrations - add basic compose file
43 lines
766 B
Go
43 lines
766 B
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"reflect"
|
|
|
|
"github.com/alecthomas/kong"
|
|
)
|
|
|
|
var _ kong.Mapper = (*PasswordMapper)(nil)
|
|
|
|
type PasswordMapper struct {
|
|
}
|
|
|
|
func (p PasswordMapper) Decode(ctx *kong.DecodeContext, target reflect.Value) error {
|
|
token := ctx.Scan.Pop()
|
|
switch v := token.Value.(type) {
|
|
case []byte:
|
|
target.SetBytes(v)
|
|
case string:
|
|
if len(v) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if v == "-" {
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
if scanner.Scan() {
|
|
target.SetBytes(scanner.Bytes())
|
|
return nil
|
|
} else {
|
|
return fmt.Errorf("failed to read password from stdin: %v", scanner.Err())
|
|
}
|
|
}
|
|
|
|
target.SetBytes([]byte(v))
|
|
default:
|
|
return fmt.Errorf("expected bool but got %q (%T)", token.Value, token.Value)
|
|
}
|
|
|
|
return nil
|
|
}
|