コード例 #1
0
ファイル: gootstrap.go プロジェクト: hgsigner/gootstrap
// Creates the custom gootFiles.
// Its a helper function.
func createCustomGootFile(packName, fileName, template, filepath string, out io.Writer) gootFile {
	currentYear, currentMonth, currentDay := time.Now().Date()
	currentDate := fmt.Sprintf("%d-%d-%d", currentYear, currentMonth, currentDay)
	user, _ := user.Current()

	fileNameTempl := CustomTemplate{PackageName: packName, Template: fileName}

	filename := filepath + fileNameTempl.Parse()

	gf := gootFile{
		fileName: filename,
		template: CustomTemplate{
			PackageName:          packName,
			HumanizedPackageName: stringfy.CamelCase(packName),
			CurrentYear:          currentYear,
			UserName:             user.Name,
			Date:                 currentDate,
			Template:             template,
		},
		okMessage: fmt.Sprintf("===> Creating %s file", filename),
		output:    out,
	}

	return gf
}
コード例 #2
0
ファイル: camelcase_test.go プロジェクト: hgsigner/stringfy
func Test_CamelCase(t *testing.T) {

	tests := []struct {
		in, out string
	}{
		{in: "fizz buzz bazz", out: "FizzBuzzBazz"},
		{in: "fizz_buzz_bazz", out: "FizzBuzzBazz"},
		{in: "fizz-buzz-bazz", out: "FizzBuzzBazz"},
		{in: "Fizz Buzz Bazz", out: "FizzBuzzBazz"},
		{in: "São Ñino França Ávido Caça", out: "SaoNinoFrancaAvidoCaca"},
	}

	for _, test := range tests {
		cc := stringfy.CamelCase(test.in)
		if cc != test.out {
			t.Errorf("\nExpected: %s\nGot:      %s", test.out, cc)
		}
	}
}
コード例 #3
0
ファイル: gootstrap.go プロジェクト: hgsigner/gootstrap
// Creates the package with files in it
func createDefaultPackage(pack_name, subcommand string, out io.Writer) error {
	sep := string(filepath.Separator)

	// Creates the project's folder
	createFolder(pack_name, out)

	// Init files

	currentYear, currentMonth, currentDay := time.Now().Date()
	currentDate := fmt.Sprintf("%d-%d-%d", currentYear, currentMonth, currentDay)
	user, _ := user.Current()

	files := filesList{
		{
			anchor:     "gitignore",
			fileName:   fmt.Sprintf("%s%s.gitignore", pack_name, sep),
			template:   GitIgnoreFile{},
			okMessage:  "===> Creating .gitignore file",
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:     "travis",
			fileName:   fmt.Sprintf("%s%s.travis.yml", pack_name, sep),
			template:   TravisFile{},
			okMessage:  "===> Creating .travis.yml file",
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:     "license",
			fileName:   fmt.Sprintf("%s%sLICENSE.txt", pack_name, sep),
			template:   LicenseFile{currentYear, user.Name},
			okMessage:  "===> Creating LICENSE.txt file",
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:     "readme",
			fileName:   fmt.Sprintf("%s%sREADME.md", pack_name, sep),
			template:   ReadmeFile{stringfy.CamelCase(pack_name), pack_name},
			okMessage:  "===> Creating README.md file",
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:     "main",
			fileName:   fmt.Sprintf("%s%s%s.go", pack_name, sep, pack_name),
			template:   MainFile{pack_name},
			okMessage:  fmt.Sprintf("===> Creating %s.go file", pack_name),
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:     "test",
			fileName:   fmt.Sprintf("%s%s%s_test.go", pack_name, sep, pack_name),
			template:   MainTestFile{pack_name},
			okMessage:  fmt.Sprintf("===> Creating %s_test.go file", pack_name),
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:   "doc",
			fileName: fmt.Sprintf("%s%sdoc.go", pack_name, sep),

			template:   DocFile{pack_name},
			okMessage:  "===> Creating doc.go file",
			output:     out,
			subcommand: subcommand,
		},
		{
			anchor:   "changelog",
			fileName: fmt.Sprintf("%s%sCHANGELOG.md", pack_name, sep),

			template:   ChangelogFile{currentDate},
			okMessage:  "===> Creating CHANGELOG.md file",
			output:     out,
			subcommand: subcommand,
		},
	}

	err := files.Process()
	if err != nil {
		return err
	}

	return nil
}