From 28be4dbc6bafbf66f0e4a1ffd0d1eae0eba9ba1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Tue, 11 Jun 2024 15:36:08 +0800 Subject: [PATCH] fix version and dep optional (#4) --- cmd/protobuild/cmd.go | 12 ++++++++++-- cmd/protobuild/config.go | 9 +++++---- version/version.go | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/protobuild/cmd.go b/cmd/protobuild/cmd.go index 0ad630b..a12238f 100644 --- a/cmd/protobuild/cmd.go +++ b/cmd/protobuild/cmd.go @@ -3,7 +3,6 @@ package protobuild import ( "bytes" "fmt" - "github.com/a8m/envsubst" "io" "io/fs" "os" @@ -12,7 +11,7 @@ import ( "strings" "sync" - _ "github.com/a8m/envsubst" + "github.com/a8m/envsubst" "github.com/cnf/structhash" "github.com/pubgo/funk/assert" "github.com/pubgo/funk/errors" @@ -340,6 +339,10 @@ func Main() *cli.App { continue } + if pathutil.IsNotExist(url) && dep.Optional != nil && *dep.Optional { + continue + } + v := strutil.FirstFnNotEmpty(func() string { return versions[url] }, func() string { @@ -422,6 +425,11 @@ func Main() *cli.App { fmt.Println(url) url = assert.Must1(filepath.Abs(url)) + + if pathutil.IsNotExist(url) && dep.Optional != nil && *dep.Optional { + continue + } + newUrl := filepath.Join(cfg.Vendor, dep.Name) assert.Must(filepath.Walk(url, func(path string, info fs.FileInfo, err error) (gErr error) { if err != nil { diff --git a/cmd/protobuild/config.go b/cmd/protobuild/config.go index 999686f..f87ea8c 100644 --- a/cmd/protobuild/config.go +++ b/cmd/protobuild/config.go @@ -39,8 +39,9 @@ type plugin struct { } type depend struct { - Name string `yaml:"name,omitempty"` - Url string `yaml:"url,omitempty"` - Path string `yaml:"path,omitempty"` - Version *string `yaml:"version,omitempty"` + Name string `yaml:"name,omitempty"` + Url string `yaml:"url,omitempty"` + Path string `yaml:"path,omitempty"` + Version *string `yaml:"version,omitempty"` + Optional *bool `yaml:"optional,omitempty"` } diff --git a/version/version.go b/version/version.go index d4ca7d8..7f743ae 100644 --- a/version/version.go +++ b/version/version.go @@ -5,7 +5,7 @@ import ( "github.com/pubgo/funk/assert" ) -var Version = "v0.0.1-dev" +var Version = "v0.0.20" func init() { if Version == "" {