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

View file

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

View file

@ -68,7 +68,7 @@ func Main() int {
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
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.")
@ -88,7 +88,7 @@ func Main() int {
case initCmd.FullCommand():
return initCommand(workdir)
case installCmd.FullCommand():
return installCommand(workdir, cfg.JsonnetHome, *installCmdURLs...)
return installCommand(workdir, cfg.JsonnetHome, *installCmdPaths...)
case updateCmd.FullCommand():
return updateCommand(cfg.JsonnetHome)
default:

View file

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