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:
parent
8aaaacc9da
commit
a6a6037d01
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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
|
||||
```
|
||||
|
Reference in New Issue
Block a user