Skip to content

Commit

Permalink
Rename configuration item package to importpathclose #9
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed Jan 22, 2017
1 parent bed76ed commit 116dff2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ It only covers the most common items, and tries to guess sensible defaults.`)
}

// optional
c.Package = gatherOne("package", "main")
c.Importpath = gatherOne("importpath", "main")
for {
c.Variables = append(c.Variables, *gatherOneVar())

Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

// Config 配置结构体
type Config struct {
Version string `json:"version"` // 版本号
Tool string `json:"tool"` // 编译工具:go、gb...
Package string `json:"package,omitempty"` // 待替换的变量所在包导入路径,如github.com/voidint/gbb/build
Variables []Variable `json:"variables,omitempty"` // 待替换变量集合
Debug bool `json:"-"`
Version string `json:"version"` // 版本号
Tool string `json:"tool"` // 编译工具:go、gb...
Importpath string `json:"importpath,omitempty"` // 待替换的变量所在包导入路径,如github.com/voidint/gbb/build
Variables []Variable `json:"variables,omitempty"` // 待替换变量集合
Debug bool `json:"-"`
}

// Variable 变量结构体
Expand Down
16 changes: 8 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestLoad(t *testing.T) {
Convey("预期配置文件存在,实际文件存在", func() {
Convey("配置文件内容为合法JSON", func() {
c := Config{
Version: "0.1.1",
Tool: "go install",
Package: "github.com/voidint/gbb/build",
Version: "0.1.1",
Tool: "go install",
Importpath: "github.com/voidint/gbb/build",
Variables: []Variable{
{Variable: "Date", Value: "{{.Date}}"},
{Variable: "Commit", Value: "{{.GitCommit}}"},
Expand All @@ -37,7 +37,7 @@ func TestLoad(t *testing.T) {
So(loadC, ShouldNotBeNil)
So(loadC.Version, ShouldEqual, c.Version)
So(loadC.Tool, ShouldEqual, c.Tool)
So(loadC.Package, ShouldEqual, c.Package)
So(loadC.Importpath, ShouldEqual, c.Importpath)
So(len(loadC.Variables), ShouldEqual, len(c.Variables))
So(loadC.Variables[0].Variable, ShouldEqual, c.Variables[0].Variable)
So(loadC.Variables[0].Value, ShouldEqual, c.Variables[0].Value)
Expand Down Expand Up @@ -78,9 +78,9 @@ func TestSave(t *testing.T) {
filename := filepath.Join(os.TempDir(), "gbb.json")
Convey("配置对象和磁盘文件都合法", func() {
c := Config{
Version: "0.1.1",
Tool: "go install",
Package: "github.com/voidint/gbb/build",
Version: "0.1.1",
Tool: "go install",
Importpath: "github.com/voidint/gbb/build",
Variables: []Variable{
{Variable: "Date", Value: "{{.Date}}"},
{Variable: "Commit", Value: "{{.GitCommit}}"},
Expand All @@ -94,7 +94,7 @@ func TestSave(t *testing.T) {
So(loadC, ShouldNotBeNil)
So(loadC.Version, ShouldEqual, c.Version)
So(loadC.Tool, ShouldEqual, c.Tool)
So(loadC.Package, ShouldEqual, c.Package)
So(loadC.Importpath, ShouldEqual, c.Importpath)
So(len(loadC.Variables), ShouldEqual, len(c.Variables))
So(loadC.Variables[0].Variable, ShouldEqual, c.Variables[0].Variable)
So(loadC.Variables[0].Value, ShouldEqual, c.Variables[0].Value)
Expand Down
2 changes: 1 addition & 1 deletion tool/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func buildDir(conf *config.Config, dir string) (err error) {
if conf.Debug {
fmt.Println(val)
}
buf.WriteString(fmt.Sprintf(`-X "%s.%s=%s"`, conf.Package, varName, val))
buf.WriteString(fmt.Sprintf(`-X "%s.%s=%s"`, conf.Importpath, varName, val))
if i < len(conf.Variables)-1 {
buf.WriteByte(' ')
}
Expand Down
14 changes: 7 additions & 7 deletions tool/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestBuild(t *testing.T) {
Convey("调用gb build编译", t, func() {
Convey("包含变量表达式", func() {
c := &config.Config{
Version: "0.3.0",
Tool: "gb build",
Package: "github.com/voidint/gbb/build",
Debug: true,
Version: "0.3.0",
Tool: "gb build",
Importpath: "github.com/voidint/gbb/build",
Debug: true,
}

Convey("包含非法变量表达式", func() {
Expand Down Expand Up @@ -58,9 +58,9 @@ func TestBuild(t *testing.T) {

Convey("调用go build编译", t, func() {
c := &config.Config{
Version: "0.3.0",
Tool: "go build",
Package: "github.com/voidint/gbb/build",
Version: "0.3.0",
Tool: "go build",
Importpath: "github.com/voidint/gbb/build",
Variables: []config.Variable{
{Variable: "Date", Value: "{{.Date}}"},
},
Expand Down

0 comments on commit 116dff2

Please sign in to comment.