cmd/plan: implemented git and dir

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-01 17:09:22 -07:00
parent 6cbea26f7f
commit c3846100b3
3 changed files with 47 additions and 9 deletions

View File

@ -1,6 +1,8 @@
package plan
import (
"dagger.io/go/cmd/dagger/logger"
"dagger.io/go/dagger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -17,10 +19,10 @@ var dirCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
// lg := logger.New()
// ctx := lg.WithContext(cmd.Context())
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
panic("not implemented")
updateDeploymentPlan(ctx, dagger.DirInput(args[0], []string{"*.cue", "cue.mod"}))
},
}

View File

@ -1,14 +1,16 @@
package plan
import (
"dagger.io/go/cmd/dagger/logger"
"dagger.io/go/dagger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var gitCmd = &cobra.Command{
Use: "git REMOTE REF [SUBDIR]",
Use: "git REMOTE [REF] [SUBDIR]",
Short: "Load plan from a git package",
Args: cobra.MinimumNArgs(2),
Args: cobra.RangeArgs(1, 3),
PreRun: func(cmd *cobra.Command, args []string) {
// Fix Viper bug for duplicate flags:
// https://github.com/spf13/viper/issues/233
@ -17,10 +19,20 @@ var gitCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
// lg := logger.New()
// ctx := lg.WithContext(cmd.Context())
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
panic("not implemented")
ref := "HEAD"
if len(args) > 1 {
ref = args[1]
}
subDir := ""
if len(args) > 2 {
subDir = args[2]
}
updateDeploymentPlan(ctx, dagger.GitInput(args[0], ref, subDir))
},
}

View File

@ -1,6 +1,13 @@
package plan
import "github.com/spf13/cobra"
import (
"context"
"dagger.io/go/cmd/dagger/cmd/common"
"dagger.io/go/dagger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
// Cmd exposes the top-level command
var Cmd = &cobra.Command{
@ -16,3 +23,20 @@ func init() {
fileCmd,
)
}
func updateDeploymentPlan(ctx context.Context, planSource dagger.Input) {
lg := log.Ctx(ctx)
store, err := dagger.DefaultStore()
if err != nil {
lg.Fatal().Err(err).Msg("failed to load store")
}
st := common.GetCurrentDeploymentState(ctx, store)
st.PlanSource = planSource
if err := store.UpdateDeployment(ctx, st, nil); err != nil {
lg.Fatal().Err(err).Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("cannot update deployment")
}
lg.Info().Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("updated deployment")
}