rename dagger.mod.cue to dagger.mod and remove the need for module name

Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com>
This commit is contained in:
Tihomir Jovicic 2021-08-24 10:16:29 +02:00
parent 8aaaacc9da
commit a6a6037d01
3 changed files with 7 additions and 39 deletions

View File

@ -16,13 +16,12 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const filePath = "./cue.mod/dagger.mod.cue" const filePath = "./cue.mod/dagger.mod"
const destBasePath = "./cue.mod/pkg" const destBasePath = "./cue.mod/pkg"
const tmpBasePath = "./cue.mod/tmp" const tmpBasePath = "./cue.mod/tmp"
// A file is the parsed, interpreted form of a cue.mod file. // A file is the parsed, interpreted form of a cue.mod file.
type file struct { type file struct {
module string
require []*require require []*require
workspacePath string workspacePath string
@ -61,18 +60,9 @@ func read(f io.Reader) (*file, error) {
lines := nonEmptyLines(b) 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 var requires []*require
for i := 1; i < len(lines); i++ { for _, line := range lines {
split := strings.Split(lines[i], " ") split := strings.Split(line, " ")
r, err := parseArgument(split[0]) r, err := parseArgument(split[0])
if err != nil { if err != nil {
return nil, err return nil, err
@ -84,7 +74,6 @@ func read(f io.Reader) (*file, error) {
} }
return &file{ return &file{
module: module,
require: requires, require: requires,
}, nil }, nil
} }
@ -184,7 +173,6 @@ func (f *file) write() error {
func (f *file) contents() *bytes.Buffer { func (f *file) contents() *bytes.Buffer {
var b bytes.Buffer var b bytes.Buffer
b.WriteString(fmt.Sprintf("module: %s\n\n", f.module))
for _, r := range f.require { for _, r := range f.require {
b.WriteString(fmt.Sprintf("%s %s\n", r.fullPath(), r.version)) b.WriteString(fmt.Sprintf("%s %s\n", r.fullPath(), r.version))
} }

View File

@ -11,25 +11,13 @@ func TestReadFile(t *testing.T) {
input string input string
want *file want *file
}{ }{
{
name: "module file without dependencies",
input: `
module: "alpha.dagger.io"
`,
want: &file{
module: "alpha.dagger.io",
},
},
{ {
name: "module file with valid dependencies", name: "module file with valid dependencies",
input: ` input: `
module: "alpha.dagger.io"
github.com/tjovicic/test xyz github.com/tjovicic/test xyz
github.com/bla/bla abc github.com/bla/bla abc
`, `,
want: &file{ want: &file{
module: "alpha.dagger.io",
require: []*require{ require: []*require{
{ {
repo: "github.com/tjovicic/test", repo: "github.com/tjovicic/test",
@ -53,10 +41,6 @@ func TestReadFile(t *testing.T) {
t.Error(err) 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) { if len(got.require) != len(c.want.require) {
t.Errorf("requires length differs: want %d, got %d", len(c.want.require), len(got.require)) t.Errorf("requires length differs: want %d, got %d", len(c.want.require), len(got.require))
} }

View File

@ -71,9 +71,7 @@ cue.mod/pkg/github.com/
└── source.cue └── source.cue
``` ```
```cue title="./cue.mod/dagger.mod.cue" ```cue title="./cue.mod/dagger.mod"
module: main
github.com/tjovicic/dagger-modules/gcpcloudrun v0.1 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: And `cue.mod/dagger.mod.cue` should reflect the new version:
```cue title="./cue.mod/dagger.mod.cue" ```cue title="./cue.mod/dagger.mod"
module: main
github.com/tjovicic/dagger-modules/gcpcloudrun v0.2 github.com/tjovicic/dagger-modules/gcpcloudrun v0.2
``` ```