mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
fix: ensure in update
moves the update command implementation to the new Ensure function
This commit is contained in:
parent
6e3e7b2fdd
commit
ffd43cf94e
2 changed files with 21 additions and 33 deletions
|
|
@ -85,7 +85,7 @@ func Main() int {
|
||||||
case installCmd.FullCommand():
|
case installCmd.FullCommand():
|
||||||
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs)
|
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs)
|
||||||
case updateCmd.FullCommand():
|
case updateCmd.FullCommand():
|
||||||
return updateCommand(cfg.JsonnetHome)
|
return updateCommand(workdir, cfg.JsonnetHome)
|
||||||
default:
|
default:
|
||||||
installCommand(workdir, cfg.JsonnetHome, []string{})
|
installCommand(workdir, cfg.JsonnetHome, []string{})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,51 +15,39 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
|
||||||
"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/pkg/jsonnetfile"
|
||||||
|
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func updateCommand(jsonnetHome string, urls ...*url.URL) int {
|
func updateCommand(dir, jsonnetHome string, urls ...*url.URL) int {
|
||||||
m, err := jsonnetfile.Load(jsonnetfile.File)
|
if dir == "" {
|
||||||
if err != nil {
|
dir = "."
|
||||||
kingpin.Fatalf("failed to load jsonnetfile: %v", err)
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(jsonnetHome, os.ModePerm)
|
jsonnetFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.File))
|
||||||
if err != nil {
|
kingpin.FatalIfError(err, "failed to load jsonnetfile")
|
||||||
kingpin.Fatalf("failed to create jsonnet home path: %v", err)
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// When updating, the lockfile is explicitly ignored.
|
kingpin.FatalIfError(
|
||||||
isLock := false
|
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
|
||||||
lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome)
|
"creating vendor folder")
|
||||||
if err != nil {
|
|
||||||
kingpin.Fatalf("failed to install: %v", err)
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := json.MarshalIndent(lock, "", " ")
|
// When updating, locks are ignored.
|
||||||
if err != nil {
|
locks := map[string]spec.Dependency{}
|
||||||
kingpin.Fatalf("failed to encode jsonnet file: %v", err)
|
locked, err := pkg.Ensure(jsonnetFile, jsonnetHome, locks)
|
||||||
return 3
|
kingpin.FatalIfError(err, "failed to install packages")
|
||||||
}
|
|
||||||
b = append(b, []byte("\n")...)
|
|
||||||
|
|
||||||
err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644)
|
|
||||||
if err != nil {
|
|
||||||
kingpin.Fatalf("failed to write lock file: %v", err)
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
|
|
||||||
|
kingpin.FatalIfError(
|
||||||
|
writeJSONFile(filepath.Join(dir, jsonnetfile.File), jsonnetFile),
|
||||||
|
"updating jsonnetfile.json")
|
||||||
|
kingpin.FatalIfError(
|
||||||
|
writeJSONFile(filepath.Join(dir, jsonnetfile.LockFile), spec.JsonnetFile{Dependencies: locked}),
|
||||||
|
"updating jsonnetfile.lock.json")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue