Accept paths instead of URLs

This commit is contained in:
Matthias Loibl 2019-07-22 18:04:24 +02:00
parent 3e85357934
commit 9110b1417d
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
4 changed files with 11 additions and 13 deletions

View file

@ -18,7 +18,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -28,7 +27,7 @@ import (
"gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
) )
func installCommand(dir, jsonnetHome string, urls ...*url.URL) int { func installCommand(dir, jsonnetHome string, paths ...string) int {
if dir == "" { if dir == "" {
dir = "." dir = "."
} }
@ -45,8 +44,8 @@ func installCommand(dir, jsonnetHome string, urls ...*url.URL) int {
return 1 return 1
} }
if len(urls) > 0 { if len(paths) > 0 {
for _, url := range urls { for _, path := range paths {
// install package specified in command // install package specified in command
// $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib // $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib
// $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet // $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet
@ -54,10 +53,9 @@ func installCommand(dir, jsonnetHome string, urls ...*url.URL) int {
// //
// github.com/(slug)/(dir) // github.com/(slug)/(dir)
urlString := url.String() newDep := parseDepedency(path)
newDep := parseDepedency(urlString)
if newDep == nil { if newDep == nil {
kingpin.Errorf("ignoring unrecognized url: %s", url) kingpin.Errorf("ignoring unrecognized path: %s", path)
continue continue
} }

View file

@ -18,7 +18,6 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -30,7 +29,7 @@ import (
func TestInstallCommand(t *testing.T) { func TestInstallCommand(t *testing.T) {
testcases := []struct { testcases := []struct {
Name string Name string
URLs []*url.URL URLs []string
ExpectedCode int ExpectedCode int
ExpectedJsonnetFile []byte ExpectedJsonnetFile []byte
ExpectedJsonnetLockFile []byte ExpectedJsonnetLockFile []byte

View file

@ -68,7 +68,7 @@ func Main() int {
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile") initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
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() installCmdPaths := installCmd.Arg("paths", "paths to packages to install, URLs or file paths").Strings()
updateCmd := a.Command(updateActionName, "Update all dependencies.") updateCmd := a.Command(updateActionName, "Update all dependencies.")
@ -88,7 +88,7 @@ func Main() int {
case initCmd.FullCommand(): case initCmd.FullCommand():
return initCommand(workdir) return initCommand(workdir)
case installCmd.FullCommand(): case installCmd.FullCommand():
return installCommand(workdir, cfg.JsonnetHome, *installCmdURLs...) return installCommand(workdir, cfg.JsonnetHome, *installCmdPaths...)
case updateCmd.FullCommand(): case updateCmd.FullCommand():
return updateCommand(cfg.JsonnetHome) return updateCommand(cfg.JsonnetHome)
default: default:

View file

@ -20,6 +20,7 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile"
"github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/jsonnet-bundler/jsonnet-bundler/spec"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -110,7 +111,7 @@ func TestLoadJsonnetfile(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
}() }()
tempFile := filepath.Join(tempDir, JsonnetFile) tempFile := filepath.Join(tempDir, jsonnetfile.File)
err = ioutil.WriteFile(tempFile, []byte(`{}`), os.ModePerm) err = ioutil.WriteFile(tempFile, []byte(`{}`), os.ModePerm)
assert.Nil(t, err) assert.Nil(t, err)
@ -128,7 +129,7 @@ func TestLoadJsonnetfile(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
}() }()
tempFile := filepath.Join(tempDir, JsonnetFile) tempFile := filepath.Join(tempDir, jsonnetfile.File)
err = ioutil.WriteFile(tempFile, []byte(jsonnetfileContent), os.ModePerm) err = ioutil.WriteFile(tempFile, []byte(jsonnetfileContent), os.ModePerm)
assert.Nil(t, err) assert.Nil(t, err)