feat(install): add --legacy-name flag

This commit is contained in:
Duologic 2022-04-04 11:00:00 +02:00
parent 3aec759b6a
commit 9e45e0a43d
2 changed files with 13 additions and 3 deletions

View file

@ -17,6 +17,7 @@ package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"reflect"
@ -30,7 +31,7 @@ import (
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
)
func installCommand(dir, jsonnetHome string, uris []string, single bool) int {
func installCommand(dir, jsonnetHome string, uris []string, single bool, legacyName string) int {
if dir == "" {
dir = "."
}
@ -53,6 +54,10 @@ func installCommand(dir, jsonnetHome string, uris []string, single bool) int {
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
"creating vendor folder")
if len(uris) > 1 && legacyName != "" {
log.Fatal("Cannot use --legacy-name with mutliple uris")
}
for _, u := range uris {
d := deps.Parse(dir, u)
if d == nil {
@ -63,6 +68,10 @@ func installCommand(dir, jsonnetHome string, uris []string, single bool) int {
d.Single = true
}
if legacyName != "" {
d.LegacyNameCompat = legacyName
}
if !depEqual(jsonnetFile.Dependencies[d.Name()], *d) {
// the dep passed on the cli is different from the jsonnetFile
jsonnetFile.Dependencies[d.Name()] = *d