Make use of File and LockFile constants of jsonnetfile package

This commit is contained in:
Matthias Loibl 2019-07-22 17:32:53 +02:00
parent 9d10f90924
commit 30a3cde870
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
2 changed files with 10 additions and 12 deletions

View file

@ -26,6 +26,7 @@ import (
"regexp" "regexp"
"github.com/jsonnet-bundler/jsonnet-bundler/pkg" "github.com/jsonnet-bundler/jsonnet-bundler/pkg"
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
"github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/jsonnet-bundler/jsonnet-bundler/spec"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
@ -218,9 +219,7 @@ func parseGithubDependency(urlString string) *spec.Dependency {
} }
func updateCommand(jsonnetHome string, urls ...*url.URL) int { func updateCommand(jsonnetHome string, urls ...*url.URL) int {
jsonnetfile := pkg.JsonnetFile m, err := pkg.LoadJsonnetfile(jsonnetfile.File)
m, err := pkg.LoadJsonnetfile(jsonnetfile)
if err != nil { if err != nil {
kingpin.Fatalf("failed to load jsonnetfile: %v", err) kingpin.Fatalf("failed to load jsonnetfile: %v", err)
return 1 return 1
@ -234,7 +233,7 @@ func updateCommand(jsonnetHome string, urls ...*url.URL) int {
// When updating, the lockfile is explicitly ignored. // When updating, the lockfile is explicitly ignored.
isLock := false isLock := false
lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile, m, jsonnetHome) lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome)
if err != nil { if err != nil {
kingpin.Fatalf("failed to install: %v", err) kingpin.Fatalf("failed to install: %v", err)
return 3 return 3
@ -247,7 +246,7 @@ func updateCommand(jsonnetHome string, urls ...*url.URL) int {
} }
b = append(b, []byte("\n")...) b = append(b, []byte("\n")...)
err = ioutil.WriteFile(pkg.JsonnetLockFile, b, 0644) err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644)
if err != nil { if err != nil {
kingpin.Fatalf("failed to write lock file: %v", err) kingpin.Fatalf("failed to write lock file: %v", err)
return 3 return 3

View file

@ -24,13 +24,12 @@ import (
"path/filepath" "path/filepath"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
"github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/jsonnet-bundler/jsonnet-bundler/spec"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var ( var (
JsonnetFile = "jsonnetfile.json"
JsonnetLockFile = "jsonnetfile.lock.json"
VersionMismatch = errors.New("multiple colliding versions specified") VersionMismatch = errors.New("multiple colliding versions specified")
) )
@ -161,18 +160,18 @@ func FileExists(path string) (bool, error) {
} }
func ChooseJsonnetFile(dir string) (string, bool, error) { func ChooseJsonnetFile(dir string) (string, bool, error) {
lockfile := path.Join(dir, JsonnetLockFile) lockfilePath := path.Join(dir, jsonnetfile.LockFile)
jsonnetfile := path.Join(dir, JsonnetFile) jsonnetfilePath := path.Join(dir, jsonnetfile.File)
filename := lockfile filename := lockfilePath
isLock := true isLock := true
lockExists, err := FileExists(filepath.Join(dir, JsonnetLockFile)) lockExists, err := FileExists(filepath.Join(dir, jsonnetfile.LockFile))
if err != nil { if err != nil {
return "", false, err return "", false, err
} }
if !lockExists { if !lockExists {
filename = jsonnetfile filename = jsonnetfilePath
isLock = false isLock = false
} }