comparison multipass.go @ 19:58fe867c9ecf

Reorganize commands to more standard go layout. - Unify multipass user commands under one 'multipass' binary - Move multipass checkpassword command to mp-checkpassword.
author Paul Fisher <paul@pfish.zone>
date Sun, 01 Nov 2015 12:42:02 -0500
parents
children
comparison
equal deleted inserted replaced
18:00d30c67b56d 19:58fe867c9ecf
1 // multipass is a command for users to manage their multipass password database.
2 //
3 // See the Usage message for more details.
4 package main
5
6 import (
7 "bufio"
8 "fmt"
9 "os"
10
11 "pfish.zone/go/multipass/file"
12 )
13
14 const Usage = `
15 multipass is a command for users to manage their multipass password databases.
16
17 Usage:
18 multipass command
19
20 The commands are:
21 add
22 remove
23
24 multipass add:
25 adds a new password to the user's multipass database.
26 Prompts the user for a description, and adds it.
27
28 multipass remove:
29 removes a password from the user's multipass database.
30 Lists the user's password, and removes the one they choose.
31 `
32
33 var commands map[string]func(*file.ShadowFile, *bufio.Reader) int
34
35 func init() {
36 commands = make(map[string]func(*file.ShadowFile, *bufio.Reader) int)
37 commands["add"] = add
38 commands["remove"] = remove
39 }
40
41 func main() {
42 if len(os.Args) != 2 {
43 usage()
44 }
45
46 cmd, ok := commands[os.Args[1]]
47 if !ok {
48 usage()
49 }
50
51 passfile, err := file.ForMe()
52 if err != nil {
53 fmt.Println(err.Error())
54 os.Exit(1)
55 }
56 input := bufio.NewReader(os.Stdin)
57 os.Exit(cmd(passfile, input))
58 }
59
60 func usage() {
61 fmt.Print(Usage)
62 os.Exit(2)
63 }