Remove state (State + Project)
Signed-off-by: Joel Longtine <joel@dagger.io>
This commit is contained in:
@@ -12,78 +12,8 @@ import (
|
||||
"go.dagger.io/dagger/client"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
func CurrentProject(ctx context.Context) *state.Project {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
if projectPath := viper.GetString("project"); projectPath != "" {
|
||||
project, err := state.Open(ctx, projectPath)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Str("path", projectPath).
|
||||
Msg("failed to open project")
|
||||
}
|
||||
return project
|
||||
}
|
||||
|
||||
project, err := state.Current(ctx)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Msg("failed to determine current project")
|
||||
}
|
||||
return project
|
||||
}
|
||||
|
||||
func CurrentEnvironmentState(ctx context.Context, project *state.Project) *state.State {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
environmentName := viper.GetString("environment")
|
||||
if environmentName != "" {
|
||||
st, err := project.Get(ctx, environmentName)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Msg("failed to load environment")
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
environments, err := project.List(ctx)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Msg("failed to list environments")
|
||||
}
|
||||
|
||||
if len(environments) == 0 {
|
||||
lg.
|
||||
Fatal().
|
||||
Msg("no environments")
|
||||
}
|
||||
|
||||
if len(environments) > 1 {
|
||||
envNames := []string{}
|
||||
for _, e := range environments {
|
||||
envNames = append(envNames, e.Name)
|
||||
}
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Strs("environments", envNames).
|
||||
Msg("multiple environments available in the project, select one with `--environment`")
|
||||
}
|
||||
|
||||
return environments[0]
|
||||
}
|
||||
|
||||
// FormatValue returns the String representation of the cue value
|
||||
func FormatValue(val *compiler.Value) string {
|
||||
switch {
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
"go.dagger.io/dagger/state"
|
||||
"go.dagger.io/dagger/telemetry"
|
||||
)
|
||||
|
||||
@@ -32,34 +31,6 @@ func commandName(cmd *cobra.Command) string {
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
// TrackProjectCommand is like TrackCommand but includes project and
|
||||
// optionally environment metadata.
|
||||
func TrackProjectCommand(ctx context.Context, cmd *cobra.Command, w *state.Project, env *state.State, props ...*telemetry.Property) chan struct{} {
|
||||
props = append([]*telemetry.Property{
|
||||
{
|
||||
// Hash the repository URL for privacy
|
||||
Name: "git_repository_hash",
|
||||
Value: hash(gitRepoURL(w.Path)),
|
||||
},
|
||||
{
|
||||
// The project path might contain the username (e.g. /home/user/project), so we hash it for privacy.
|
||||
Name: "project_path_hash",
|
||||
Value: hash(w.Path),
|
||||
},
|
||||
}, props...)
|
||||
|
||||
if env != nil {
|
||||
props = append([]*telemetry.Property{
|
||||
{
|
||||
Name: "environment_name",
|
||||
Value: env.Name,
|
||||
},
|
||||
}, props...)
|
||||
}
|
||||
|
||||
return TrackCommand(ctx, cmd, props...)
|
||||
}
|
||||
|
||||
// hash returns the sha256 digest of the string
|
||||
func hash(s string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(s)))
|
||||
|
@@ -5,9 +5,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/state"
|
||||
"go.dagger.io/dagger/pkg"
|
||||
)
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
@@ -37,12 +36,13 @@ var initCmd = &cobra.Command{
|
||||
dir = cwd
|
||||
}
|
||||
|
||||
project, err := state.Init(ctx, dir)
|
||||
err := pkg.CueModInit(ctx, dir)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to initialize project")
|
||||
}
|
||||
|
||||
<-common.TrackProjectCommand(ctx, cmd, project, nil)
|
||||
// TODO: Add telemtry for init
|
||||
// <-common.TrackProjectCommand(ctx, cmd, project, nil)
|
||||
|
||||
},
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/mod"
|
||||
"go.dagger.io/dagger/pkg"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
var getCmd = &cobra.Command{
|
||||
@@ -28,10 +27,10 @@ var getCmd = &cobra.Command{
|
||||
var err error
|
||||
|
||||
cueModPath := pkg.GetCueModParent()
|
||||
// err = pkg.CueModInit(ctx, cueModPath)
|
||||
_, err = state.Init(ctx, cueModPath)
|
||||
if err != nil && err != state.ErrAlreadyInit {
|
||||
err = pkg.CueModInit(ctx, cueModPath)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to initialize cue.mod")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var update = viper.GetBool("update")
|
||||
|
Reference in New Issue
Block a user