Example #1
0
func MakeConfig() os.Error {
	var (
		c       = config.NewDefault()
		scanner = bufio.NewReader(os.Stdin)
		errScan os.Error
		buff    []byte
	)
	fmt.Printf("Enter your name: ")
	buff, _, errScan = scanner.ReadLine()
	if errScan != nil {
		return errScan
	}
	c.AddOption("variables", "name", string(bytes.TrimRight(buff, "\n")))
	fmt.Printf("Enter your email address: ")
	buff, _, errScan = scanner.ReadLine()
	if errScan != nil {
		return errScan
	}
	c.AddOption("variables", "email", string(bytes.TrimRight(buff, "\n")))
	var (
		repoName string
		repoOk   bool
	)
	for !repoOk {
		fmt.Printf("Enter a repository type ('git', or none): ")
		buff, _, errScan = scanner.ReadLine()
		if errScan != nil {
			return errScan
		}
		repoName = string(bytes.TrimRight(buff, "\n"))
		switch repoName {
		case "":
			fallthrough
		case "git":
			repoOk = true
		default:
			fmt.Printf("I didn't understand repo type %s\n", repoName)
		}
	}
	c.AddOption("general", "repo", repoName)
	var (
		hostName string
		hostOk   bool
	)
	for !hostOk {
		fmt.Printf("Enter a repo host ('github', or none): ")
		buff, _, errScan = scanner.ReadLine()
		if errScan != nil {
			return errScan
		}
		hostName = string(bytes.TrimRight(buff, "\n"))
		switch hostName {
		case "":
			fallthrough
		case "github":
			hostOk = true
		default:
			fmt.Printf("I didn't understand repo host %s\n", hostName)
		}
	}
	c.AddOption("general", "host", hostName)
	var hostuser = ""
	var hostuserOk = hostName != "github"
	for !hostuserOk {
		fmt.Printf("Enter a %s username: "******"\n"))
		if hostuser == "" {
			fmt.Printf("Invalid %s username '%s'\n", hostName, hostuser)
		} else {
			hostuserOk = true
		}
	}
	c.AddOption("general", "hostuser", hostuser)
	return c.WriteFile(ConfigFilename, FilePermissions, "Generated configuration for gonew.")
}
Example #2
0
func MakeConfig() error {
	c := config.NewDefault()
	scanner := bufio.NewReader(os.Stdin)

	var (
		err  error
		buff []byte
	)
	fmt.Printf("Enter your name: ")
	if buff, _, err = scanner.ReadLine(); err != nil {
		return err
	}
	c.AddOption("variables", "name", string(bytes.TrimRight(buff, "\n")))

	fmt.Printf("Enter your email address: ")
	if buff, _, err = scanner.ReadLine(); err != nil {
		return err
	}
	c.AddOption("variables", "email", string(bytes.TrimRight(buff, "\n")))

	var repoName string
	for repoOk := false; !repoOk; {
		fmt.Printf("Enter a repository type ('git', or none): ")
		if buff, _, err = scanner.ReadLine(); err != nil {
			return err
		}
		repoName = string(bytes.TrimRight(buff, "\n"))
		switch repoName {
		case "":
			fallthrough
		case "git":
			repoOk = true
		default:
			fmt.Printf("I didn't understand repo type %s\n", repoName)
		}
	}
	c.AddOption("general", "repo", repoName)

	var hostName string
	for hostOk := false; !hostOk; {
		fmt.Printf("Enter a repo host ('github', or none): ")
		if buff, _, err = scanner.ReadLine(); err != nil {
			return err
		}
		hostName = string(bytes.TrimRight(buff, "\n"))
		switch hostName {
		case "":
			fallthrough
		case "github":
			hostOk = true
		default:
			fmt.Printf("I didn't understand repo host %s\n", hostName)
		}
	}
	c.AddOption("general", "host", hostName)

	var hostuser string
	for hostuserOk := hostName != "github"; !hostuserOk; {
		fmt.Printf("Enter a %s username: "******"\n"))
		if hostuser == "" {
			fmt.Printf("Invalid %s username '%s'\n", hostName, hostuser)
		} else {
			hostuserOk = true
		}
	}
	c.AddOption("general", "hostuser", hostuser)

	var license string
	for licenseOK := false; !licenseOK; {
		fmt.Print("Enter a license type ('newbsd', or none): ")
		if buff, _, err = scanner.ReadLine(); err != nil {
			return err
		}
		license = string(bytes.TrimRight(buff, "\n"))
		switch license {
		case "":
			fallthrough
		case "newbsd":
			licenseOK = true
		default:
			fmt.Printf("Invalid %s username '%s'\n", hostName, hostuser)
		}
	}
	c.AddOption("general", "license", license)

	return c.WriteFile(ConfigFilename, FilePermissions, "Generated configuration for gonew.")
}