mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
Add update command
This commit is contained in:
parent
74c4caa0cf
commit
35b10d3381
2 changed files with 44 additions and 0 deletions
|
|
@ -36,5 +36,8 @@ Commands:
|
||||||
install [<packages>...]
|
install [<packages>...]
|
||||||
Install all dependencies or install specific ones
|
Install all dependencies or install specific ones
|
||||||
|
|
||||||
|
update
|
||||||
|
Update all dependencies.
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
installActionName = "install"
|
installActionName = "install"
|
||||||
|
updateActionName = "update"
|
||||||
initActionName = "init"
|
initActionName = "init"
|
||||||
basePath = ".jsonnetpkg"
|
basePath = ".jsonnetpkg"
|
||||||
srcDirName = "src"
|
srcDirName = "src"
|
||||||
|
|
@ -76,6 +77,8 @@ func Main() int {
|
||||||
installCmd := a.Command(installActionName, "Install all dependencies or install specific ones")
|
installCmd := a.Command(installActionName, "Install all dependencies or install specific ones")
|
||||||
installCmdURLs := installCmd.Arg("packages", "URLs to package to install").URLList()
|
installCmdURLs := installCmd.Arg("packages", "URLs to package to install").URLList()
|
||||||
|
|
||||||
|
updateCmd := a.Command(updateActionName, "Update all dependencies.")
|
||||||
|
|
||||||
command, err := a.Parse(os.Args[1:])
|
command, err := a.Parse(os.Args[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments"))
|
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments"))
|
||||||
|
|
@ -88,6 +91,8 @@ func Main() int {
|
||||||
return initCommand()
|
return initCommand()
|
||||||
case installCmd.FullCommand():
|
case installCmd.FullCommand():
|
||||||
return installCommand(cfg.JsonnetHome, *installCmdURLs...)
|
return installCommand(cfg.JsonnetHome, *installCmdURLs...)
|
||||||
|
case updateCmd.FullCommand():
|
||||||
|
return updateCommand(cfg.JsonnetHome)
|
||||||
default:
|
default:
|
||||||
installCommand(cfg.JsonnetHome)
|
installCommand(cfg.JsonnetHome)
|
||||||
}
|
}
|
||||||
|
|
@ -318,3 +323,39 @@ func installCommand(jsonnetHome string, urls ...*url.URL) int {
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateCommand(jsonnetHome string, urls ...*url.URL) int {
|
||||||
|
jsonnetfile := pkg.JsonnetFile
|
||||||
|
|
||||||
|
m, err := pkg.LoadJsonnetfile(jsonnetfile)
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Fatalf("failed to load jsonnetfile: %v", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(jsonnetHome, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Fatalf("failed to create jsonnet home path: %v", err)
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
lock, err := pkg.Install(context.TODO(), jsonnetfile, m, jsonnetHome)
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Fatalf("failed to install: %v", err)
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.MarshalIndent(lock, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Fatalf("failed to encode jsonnet file: %v", err)
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(pkg.JsonnetLockFile, b, 0644)
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Fatalf("failed to write lock file: %v", err)
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue