mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
Extract cmd/jb/init.go
This commit is contained in:
parent
5fdb88b6f0
commit
7560a1075c
2 changed files with 32 additions and 20 deletions
32
cmd/jb/init.go
Normal file
32
cmd/jb/init.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/jsonnet-bundler/jsonnet-bundler/pkg"
|
||||||
|
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
|
||||||
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initCommand(dir string) int {
|
||||||
|
exists, err := pkg.FileExists(jsonnetfile.File)
|
||||||
|
if err != nil {
|
||||||
|
kingpin.Errorf("Failed to check for jsonnetfile.json: %v", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
kingpin.Errorf("jsonnetfile.json already exists")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := filepath.Join(dir, jsonnetfile.File)
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filename, []byte("{}\n"), 0644); err != nil {
|
||||||
|
kingpin.Errorf("Failed to write new jsonnetfile.json: %v", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
@ -100,26 +100,6 @@ func Main() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func initCommand() int {
|
|
||||||
exists, err := pkg.FileExists(pkg.JsonnetFile)
|
|
||||||
if err != nil {
|
|
||||||
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("{}\n"), 0644); err != nil {
|
|
||||||
kingpin.Errorf("Failed to write new jsonnetfile.json: %v", err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseDepedency(urlString string) *spec.Dependency {
|
func parseDepedency(urlString string) *spec.Dependency {
|
||||||
if spec := parseGitSSHDependency(urlString); spec != nil {
|
if spec := parseGitSSHDependency(urlString); spec != nil {
|
||||||
return spec
|
return spec
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue