comparison add.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 cmds/multipass-add/add.go@00d30c67b56d
children
comparison
equal deleted inserted replaced
18:00d30c67b56d 19:58fe867c9ecf
1 // multipass-add allows a user to add an entry to their multipass database.
2
3 package main
4
5 import (
6 "bufio"
7 "fmt"
8 "os"
9
10 "pfish.zone/go/multipass/file"
11 )
12
13 func add(passfile *file.ShadowFile, input *bufio.Reader) int {
14 reader := bufio.NewReader(os.Stdin)
15 fmt.Print("Describe password: ")
16 text, err := reader.ReadString('\n')
17 if err != nil {
18 fmt.Println(err.Error())
19 return 1
20 }
21 text = text[:len(text)-1]
22 entry, password, err := file.NewEntry(text)
23 if err != nil {
24 fmt.Println(err.Error())
25 return 1
26 }
27 err = passfile.Add(entry)
28 if err != nil {
29 fmt.Println("Couldn't create a password:")
30 fmt.Println(err.Error())
31 return 1
32 }
33 fmt.Printf("New password: %s\n", password)
34 return 0
35 }