diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/multipass.go	Sun Nov 01 12:42:02 2015 -0500
@@ -0,0 +1,63 @@
+// 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)
+}