mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 16:10:04 +01:00
Merge pull request #15 from metalmatze/init-warning
Check for existing jsonnetfile.json before init
This commit is contained in:
commit
49e110fd83
3 changed files with 16 additions and 7 deletions
2
Makefile
2
Makefile
|
|
@ -23,7 +23,7 @@ build:
|
||||||
|
|
||||||
install: build
|
install: build
|
||||||
@$(eval OUTPUT=$(OUT_DIR)/$(GOOS)/$(GOARCH)/$(BIN))
|
@$(eval OUTPUT=$(OUT_DIR)/$(GOOS)/$(GOARCH)/$(BIN))
|
||||||
@echo ">> copying $(BIN) into $(GOPATH)/$(BIN)"
|
@echo ">> copying $(BIN) into $(GOPATH)/bin/$(BIN)"
|
||||||
@cp $(OUTPUT) $(GOPATH)/bin/$(BIN)
|
@cp $(OUTPUT) $(GOPATH)/bin/$(BIN)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|
|
||||||
|
|
@ -101,9 +101,19 @@ func Main() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initCommand() int {
|
func initCommand() int {
|
||||||
err := ioutil.WriteFile(pkg.JsonnetFile, []byte("{}"), 0644)
|
exists, err := pkg.FileExists(pkg.JsonnetFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
kingpin.Fatalf("Failed to write new jsonnetfile.json: %v", err)
|
kingpin.Errorf("Failed to check for jsonnetfile.json: %v", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
kingpin.Errorf("jsonnetfile.json already exists")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(pkg.JsonnetFile, []byte("{}"), 0644); err != nil {
|
||||||
|
kingpin.Errorf("Failed to write new jsonnetfile.json: %v", err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,9 +147,8 @@ func insertDependency(deps []spec.Dependency, newDep spec.Dependency) ([]spec.De
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LockExists(dir string) (bool, error) {
|
func FileExists(path string) (bool, error) {
|
||||||
lockfile := path.Join(dir, JsonnetLockFile)
|
_, err := os.Stat(path)
|
||||||
_, err := os.Stat(lockfile)
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +165,7 @@ func ChooseJsonnetFile(dir string) (string, bool, error) {
|
||||||
filename := lockfile
|
filename := lockfile
|
||||||
isLock := true
|
isLock := true
|
||||||
|
|
||||||
lockExists, err := LockExists(dir)
|
lockExists, err := FileExists(filepath.Join(dir, JsonnetLockFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue