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