Mercurial > go > multipass
view multipass.go @ 20:ef2ef22ca4b1 default tip
Add pfish.zone/go/multipass/file import directive to 'file' package.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 01 Nov 2015 13:00:54 -0500 |
parents | 58fe867c9ecf |
children |
line wrap: on
line source
// multipass is a command for users to manage their multipass password database. // // See the Usage message for more details. package main import ( "bufio" "fmt" "os" "pfish.zone/go/multipass/file" ) const Usage = ` multipass is a command for users to manage their multipass password databases. Usage: multipass command The commands are: add remove multipass add: adds a new password to the user's multipass database. Prompts the user for a description, and adds it. multipass remove: removes a password from the user's multipass database. Lists the user's password, and removes the one they choose. ` var commands map[string]func(*file.ShadowFile, *bufio.Reader) int func init() { commands = make(map[string]func(*file.ShadowFile, *bufio.Reader) int) commands["add"] = add commands["remove"] = remove } func main() { if len(os.Args) != 2 { usage() } cmd, ok := commands[os.Args[1]] if !ok { usage() } passfile, err := file.ForMe() if err != nil { fmt.Println(err.Error()) os.Exit(1) } input := bufio.NewReader(os.Stdin) os.Exit(cmd(passfile, input)) } func usage() { fmt.Print(Usage) os.Exit(2) }