view 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
line wrap: on
line source

// multipass-add allows a user to add an entry to their multipass database.

package main

import (
	"bufio"
	"fmt"
	"os"

	"pfish.zone/go/multipass/file"
)

func add(passfile *file.ShadowFile, input *bufio.Reader) int {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Describe password: ")
	text, err := reader.ReadString('\n')
	if err != nil {
		fmt.Println(err.Error())
		return 1
	}
	text = text[:len(text)-1]
	entry, password, err := file.NewEntry(text)
	if err != nil {
		fmt.Println(err.Error())
		return 1
	}
	err = passfile.Add(entry)
	if err != nil {
		fmt.Println("Couldn't create a password:")
		fmt.Println(err.Error())
		return 1
	}
	fmt.Printf("New password: %s\n", password)
	return 0
}