Extract cmd/jb/init.go

This commit is contained in:
Matthias Loibl 2019-04-24 18:17:19 +02:00
parent 5fdb88b6f0
commit 7560a1075c
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
2 changed files with 32 additions and 20 deletions

32
cmd/jb/init.go Normal file
View 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
}

View file

@ -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