From a6a6037d01491dab2c229ef13ab8dcba98252e9a Mon Sep 17 00:00:00 2001 From: Tihomir Jovicic Date: Tue, 24 Aug 2021 10:16:29 +0200 Subject: [PATCH] rename dagger.mod.cue to dagger.mod and remove the need for module name Signed-off-by: Tihomir Jovicic --- cmd/dagger/cmd/mod/file.go | 18 +++--------------- cmd/dagger/cmd/mod/file_test.go | 16 ---------------- docs/learn/1011-package-manager.md | 12 ++++-------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/cmd/dagger/cmd/mod/file.go b/cmd/dagger/cmd/mod/file.go index 21a69f08..969f69e7 100644 --- a/cmd/dagger/cmd/mod/file.go +++ b/cmd/dagger/cmd/mod/file.go @@ -16,13 +16,12 @@ import ( "github.com/spf13/viper" ) -const filePath = "./cue.mod/dagger.mod.cue" +const filePath = "./cue.mod/dagger.mod" const destBasePath = "./cue.mod/pkg" const tmpBasePath = "./cue.mod/tmp" // A file is the parsed, interpreted form of a cue.mod file. type file struct { - module string require []*require workspacePath string @@ -61,18 +60,9 @@ func read(f io.Reader) (*file, error) { lines := nonEmptyLines(b) - if len(lines) == 0 { - return nil, fmt.Errorf("cue.mod/dagger.mod.cue file is empty, missing module name") - } - - var module string - if split := strings.Split(lines[0], " "); len(split) > 1 { - module = strings.Trim(split[1], "\"") - } - var requires []*require - for i := 1; i < len(lines); i++ { - split := strings.Split(lines[i], " ") + for _, line := range lines { + split := strings.Split(line, " ") r, err := parseArgument(split[0]) if err != nil { return nil, err @@ -84,7 +74,6 @@ func read(f io.Reader) (*file, error) { } return &file{ - module: module, require: requires, }, nil } @@ -184,7 +173,6 @@ func (f *file) write() error { func (f *file) contents() *bytes.Buffer { var b bytes.Buffer - b.WriteString(fmt.Sprintf("module: %s\n\n", f.module)) for _, r := range f.require { b.WriteString(fmt.Sprintf("%s %s\n", r.fullPath(), r.version)) } diff --git a/cmd/dagger/cmd/mod/file_test.go b/cmd/dagger/cmd/mod/file_test.go index 27fd91f1..1b1c5a4d 100644 --- a/cmd/dagger/cmd/mod/file_test.go +++ b/cmd/dagger/cmd/mod/file_test.go @@ -11,25 +11,13 @@ func TestReadFile(t *testing.T) { input string want *file }{ - { - name: "module file without dependencies", - input: ` - module: "alpha.dagger.io" - `, - want: &file{ - module: "alpha.dagger.io", - }, - }, { name: "module file with valid dependencies", input: ` - module: "alpha.dagger.io" - github.com/tjovicic/test xyz github.com/bla/bla abc `, want: &file{ - module: "alpha.dagger.io", require: []*require{ { repo: "github.com/tjovicic/test", @@ -53,10 +41,6 @@ func TestReadFile(t *testing.T) { t.Error(err) } - if got.module != c.want.module { - t.Errorf("module names differ: want %s, got %s", c.want.module, got.module) - } - if len(got.require) != len(c.want.require) { t.Errorf("requires length differs: want %d, got %d", len(c.want.require), len(got.require)) } diff --git a/docs/learn/1011-package-manager.md b/docs/learn/1011-package-manager.md index 431faf5e..c0679930 100644 --- a/docs/learn/1011-package-manager.md +++ b/docs/learn/1011-package-manager.md @@ -52,13 +52,13 @@ import ( run: gcpcloudrun.#Run ``` -To install it just run +To install it just run ```shell dagger mod get github.com/tjovicic/dagger-modules/gcpcloudrun@v0.1 ``` -It should pull the `v0.1` version from Github, leave a copy in `cue.mod/pkg` and reflect the change in +It should pull the `v0.1` version from Github, leave a copy in `cue.mod/pkg` and reflect the change in `cue.mod/dagger.mod.cue` file: ```shell @@ -71,9 +71,7 @@ cue.mod/pkg/github.com/ └── source.cue ``` -```cue title="./cue.mod/dagger.mod.cue" -module: main - +```cue title="./cue.mod/dagger.mod" github.com/tjovicic/dagger-modules/gcpcloudrun v0.1 ``` @@ -115,8 +113,6 @@ You should see similar output: And `cue.mod/dagger.mod.cue` should reflect the new version: -```cue title="./cue.mod/dagger.mod.cue" -module: main - +```cue title="./cue.mod/dagger.mod" github.com/tjovicic/dagger-modules/gcpcloudrun v0.2 ```