Esempio n. 1
0
func (ic *InitCommand) Run() error {

	ic.Pkg = &common.PackageWrapper{Package: common.NewPackage()}

	// TODO: Check ~/.gitconfig for name/email
	ic.Pkg.Author.Name = <-Prompt("Your name:", ic.Pkg.Author.Name)
	ic.Pkg.Author.Email = <-Prompt("Your email:", ic.Pkg.Author.Email)

	cwd, err := os.Getwd()
	if err != nil {
		ic.Error(err)
		cwd = ""
	} else {
		cwd = filepath.Base(cwd)
	}
	ic.Pkg.Name = <-Prompt("Unique package name:", cwd)
	ic.Pkg.Version.Label = <-Prompt("Initial version:", ic.Pkg.Version.Label)

	ic.Pkg.Repository.Url = <-Prompt("Repository:", "")

	if err := ic.Pkg.Save(); err != nil {
		return err
	}

	bootstrap := <-Prompt("Generate boilerplate:", "Y/n")
	if len(bootstrap) == 0 || strings.ToLower(string(bootstrap[0])) == "y" {
		ic.GenerateBoilerplate()
		ic.license("mit") // FIXME: add support for more licenses
	}
	return nil
}
Esempio n. 2
0
File: init.go Progetto: benlau/qpm
func (ic *InitCommand) Run() error {

	ic.Pkg = &common.PackageWrapper{Package: common.NewPackage()}

	ic.Pkg.Author.Name, _ = vcs.LastCommitAuthorName()
	ic.Pkg.Author.Name, _ = <-Prompt("Your name:", ic.Pkg.Author.Name)

	ic.Pkg.Author.Email, _ = vcs.LastCommitEmail()
	ic.Pkg.Author.Email = <-Prompt("Your email:", ic.Pkg.Author.Email)

	cwd, err := os.Getwd()
	if err != nil {
		ic.Error(err)
		cwd = ""
	} else {
		cwd = filepath.Base(cwd)
	}

	suggestedName := extractReverseDomain(ic.Pkg.Author.Email) + "." + cwd

	ic.Pkg.Name = <-Prompt("Unique package name:", suggestedName)
	ic.Pkg.Version.Label = <-Prompt("Initial version:", ic.Pkg.Version.Label)

	ic.Pkg.Repository.Url, err = vcs.RepositoryURL()
	if err != nil {
		fmt.Println("WARNING: Could not auto-detect repository URL.")
	}

	ic.Pkg.Repository.Url = <-Prompt("Clone URL:", ic.Pkg.Repository.Url)

	filename, _ := ic.findPriFile()
	if len(filename) == 0 {
		filename = ic.Pkg.PriFile()
	}

	license := <-Prompt("License:", "MIT")

	// convert Github style license strings
	license = strings.ToUpper(regexGitHubLicense.ReplaceAllString(license, "_"))

	if licenseType, err := msg.LicenseType_value[license]; !err {
		errMsg := fmt.Sprintf("ERROR: Non-supported license type: %s\n", license)
		fmt.Print(errMsg)
		fmt.Printf("Valid values are:\n")
		for i := 0; i < len(msg.LicenseType_name); i++ {
			fmt.Println("\t" + msg.LicenseType_name[int32(i)])
		}
		return errors.New(errMsg)
	} else {
		ic.Pkg.License = msg.LicenseType(licenseType)
	}

	ic.Pkg.PriFilename = <-Prompt("Package .pri file:", filename)

	if err := ic.Pkg.Save(); err != nil {
		ic.Error(err)
		return err
	}

	bootstrap := <-Prompt("Generate boilerplate:", "Y/n")
	if len(bootstrap) == 0 || strings.ToLower(string(bootstrap[0])) == "y" {
		if err := ic.GenerateBoilerplate(); err != nil {
			return err
		}

		ic.GenerateLicense()
	}
	return nil
}