cli: moved abs path resolve to input.go

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-02 17:14:01 -07:00
parent e6b0ca5109
commit a799dd05d7
3 changed files with 10 additions and 13 deletions

View File

@ -1,8 +1,6 @@
package input package input
import ( import (
"path/filepath"
"dagger.io/go/cmd/dagger/logger" "dagger.io/go/cmd/dagger/logger"
"dagger.io/go/dagger" "dagger.io/go/dagger"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -24,12 +22,7 @@ var dirCmd = &cobra.Command{
lg := logger.New() lg := logger.New()
ctx := lg.WithContext(cmd.Context()) ctx := lg.WithContext(cmd.Context())
path, err := filepath.Abs(args[1]) updateDeploymentInput(ctx, args[0], dagger.DirInput(args[1], []string{}))
if err != nil {
lg.Error().Err(err).Str("path", args[1]).Msg("cannot get absolute path")
}
updateDeploymentInput(ctx, args[0], dagger.DirInput(path, []string{}))
}, },
} }

View File

@ -103,11 +103,7 @@ func getPlanSource(ctx context.Context) dagger.Input {
if planDir != "" { if planDir != "" {
checkFirstSet() checkFirstSet()
path, err := filepath.Abs(planDir) src = dagger.DirInput(planDir, []string{"*.cue", "cue.mod"})
if err != nil {
lg.Error().Err(err).Str("path", planDir).Msg("cannot get absolute path")
}
src = dagger.DirInput(path, []string{"*.cue", "cue.mod"})
} }
if planGit != "" { if planGit != "" {

View File

@ -3,6 +3,7 @@ package dagger
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"path/filepath"
"dagger.io/go/dagger/compiler" "dagger.io/go/dagger/compiler"
) )
@ -82,6 +83,13 @@ type dirInput struct {
func (dir dirInput) Compile() (*compiler.Value, error) { func (dir dirInput) Compile() (*compiler.Value, error) {
// FIXME: serialize an intermediate struct, instead of generating cue source // FIXME: serialize an intermediate struct, instead of generating cue source
// resolve absolute path
path, err := filepath.Abs(dir.Path)
if err != nil {
return nil, err
}
dir.Path = path
// json.Marshal([]string{}) returns []byte("null"), which wreaks havoc // json.Marshal([]string{}) returns []byte("null"), which wreaks havoc
// in Cue because `null` is not a `[...string]` // in Cue because `null` is not a `[...string]`
includeLLB := []byte("[]") includeLLB := []byte("[]")