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"
)
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))
}

View File

@ -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))
}

View File

@ -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
```