mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
feat(cli): --version using ldflags
The go-modules approach is a bit broken: https://github.com/golang/go/issues/29228 To resolve that, we now compute that version using `git describe` and set it using `ldflags`. While this is not as nice/builtin as the other approach, it at least works all the time and across go versions. Furthermore, I did refactor the Makefile in preparation for an AUR package that builds from source and for building release artifacts in CI.
This commit is contained in:
parent
f8be6a936f
commit
80c06a483a
4 changed files with 37 additions and 83 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/fatih/color"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -30,6 +31,8 @@ const (
|
|||
rewriteActionName = "rewrite"
|
||||
)
|
||||
|
||||
var Version = "dev"
|
||||
|
||||
func main() {
|
||||
os.Exit(Main())
|
||||
}
|
||||
|
|
@ -41,7 +44,7 @@ func Main() int {
|
|||
|
||||
color.Output = color.Error
|
||||
|
||||
a := newApp()
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager").Version(Version)
|
||||
a.HelpFlag.Short('h')
|
||||
|
||||
a.Flag("jsonnetpkg-home", "The directory used to cache packages in.").
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build go1.12
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func newApp() *kingpin.Application {
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
d, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
return a.Version(d.Main.Version)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !go1.12
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func newApp() *kingpin.Application {
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
return a
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue