Use URI as name for packages location paths

This commit is contained in:
Matthias Loibl 2019-08-12 17:39:09 +02:00
parent 6ed6c3f3ec
commit d3bb1f4ea4
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
4 changed files with 16 additions and 16 deletions

View file

@ -27,7 +27,7 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)
func installCommand(dir, jsonnetHome string, paths ...string) int {
func installCommand(dir, jsonnetHome string, uris ...string) int {
if dir == "" {
dir = "."
}
@ -44,11 +44,11 @@ func installCommand(dir, jsonnetHome string, paths ...string) int {
return 1
}
if len(paths) > 0 {
for _, path := range paths {
newDep := parseDependency(dir, path)
if len(uris) > 0 {
for _, uri := range uris {
newDep := parseDependency(dir, uri)
if newDep == nil {
kingpin.Errorf("ignoring unrecognized path: %s", path)
kingpin.Errorf("ignoring unrecognized uri: %s", uri)
continue
}

View file

@ -29,7 +29,7 @@ import (
func TestInstallCommand(t *testing.T) {
testcases := []struct {
Name string
URLs []string
URIs []string
ExpectedCode int
ExpectedJsonnetFile []byte
ExpectedJsonnetLockFile []byte
@ -41,13 +41,13 @@ func TestInstallCommand(t *testing.T) {
ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`),
}, {
Name: "OneURL",
URLs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
ExpectedCode: 0,
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}]}`),
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`),
}, {
Name: "Relative",
URLs: []string{"test/jsonnet/foobar"},
URIs: []string{"test/jsonnet/foobar"},
ExpectedCode: 0,
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
@ -71,7 +71,7 @@ func TestInstallCommand(t *testing.T) {
jsonnetFileContent(t, jsonnetFile, []byte(`{}`))
code = installCommand(tempDir, "vendor", tc.URLs...)
code = installCommand(tempDir, "vendor", tc.URIs...)
assert.Equal(t, tc.ExpectedCode, code)
jsonnetFileContent(t, jsonnetFile, tc.ExpectedJsonnetFile)

View file

@ -63,7 +63,7 @@ func Main() int {
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
installCmd := a.Command(installActionName, "Install all dependencies or install specific ones")
installCmdPaths := installCmd.Arg("paths", "paths to packages to install, URLs or file paths").Strings()
installCmdURIs := installCmd.Arg("uris", "URIs to packages to install, URLs or file paths").Strings()
updateCmd := a.Command(updateActionName, "Update all dependencies.")
@ -83,7 +83,7 @@ func Main() int {
case initCmd.FullCommand():
return initCommand(workdir)
case installCmd.FullCommand():
return installCommand(workdir, cfg.JsonnetHome, *installCmdPaths...)
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs...)
case updateCmd.FullCommand():
return updateCommand(cfg.JsonnetHome)
default:
@ -93,16 +93,16 @@ func Main() int {
return 0
}
func parseDependency(dir, path string) *spec.Dependency {
if d := parseGitSSHDependency(path); d != nil {
func parseDependency(dir, uri string) *spec.Dependency {
if d := parseGitSSHDependency(uri); d != nil {
return d
}
if d := parseGithubDependency(path); d != nil {
if d := parseGithubDependency(uri); d != nil {
return d
}
if d := parseLocalDependency(dir, path); d != nil {
if d := parseLocalDependency(dir, uri); d != nil {
return d
}