From 7061ac816e04d62dab6fcf4a8e749d7a0293c220 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 23 Sep 2021 12:02:57 -0600 Subject: [PATCH] changed workspace to project Signed-off-by: Richard Jones --- cmd/dagger/cmd/common/common.go | 26 +++++++------- cmd/dagger/cmd/common/track.go | 8 ++--- cmd/dagger/cmd/edit.go | 8 ++--- cmd/dagger/cmd/init.go | 10 +++--- cmd/dagger/cmd/input/dir.go | 8 ++--- cmd/dagger/cmd/input/list.go | 6 ++-- cmd/dagger/cmd/input/root.go | 8 ++--- cmd/dagger/cmd/input/unset.go | 6 ++-- cmd/dagger/cmd/list.go | 6 ++-- cmd/dagger/cmd/mod/file.go | 14 ++++---- cmd/dagger/cmd/mod/get.go | 8 ++--- cmd/dagger/cmd/new.go | 6 ++-- cmd/dagger/cmd/output/list.go | 6 ++-- cmd/dagger/cmd/query.go | 6 ++-- cmd/dagger/cmd/root.go | 2 +- cmd/dagger/cmd/up.go | 8 ++--- state/input.go | 6 ++-- state/{workspace.go => project.go} | 32 ++++++++--------- state/{workspace_test.go => project_test.go} | 38 ++++++++++---------- state/state.go | 12 +++---- 20 files changed, 112 insertions(+), 112 deletions(-) rename state/{workspace.go => project.go} (90%) rename state/{workspace_test.go => project_test.go} (75%) diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index dd7e2503..9d4e1997 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -13,37 +13,37 @@ import ( "go.dagger.io/dagger/state" ) -func CurrentWorkspace(ctx context.Context) *state.Workspace { +func CurrentProject(ctx context.Context) *state.Project { lg := log.Ctx(ctx) - if workspacePath := viper.GetString("workspace"); workspacePath != "" { - workspace, err := state.Open(ctx, workspacePath) + if projectPath := viper.GetString("project"); projectPath != "" { + project, err := state.Open(ctx, projectPath) if err != nil { lg. Fatal(). Err(err). - Str("path", workspacePath). - Msg("failed to open workspace") + Str("path", projectPath). + Msg("failed to open project") } - return workspace + return project } - workspace, err := state.Current(ctx) + project, err := state.Current(ctx) if err != nil { lg. Fatal(). Err(err). - Msg("failed to determine current workspace") + Msg("failed to determine current project") } - return workspace + return project } -func CurrentEnvironmentState(ctx context.Context, workspace *state.Workspace) *state.State { +func CurrentEnvironmentState(ctx context.Context, project *state.Project) *state.State { lg := log.Ctx(ctx) environmentName := viper.GetString("environment") if environmentName != "" { - st, err := workspace.Get(ctx, environmentName) + st, err := project.Get(ctx, environmentName) if err != nil { lg. Fatal(). @@ -53,7 +53,7 @@ func CurrentEnvironmentState(ctx context.Context, workspace *state.Workspace) *s return st } - environments, err := workspace.List(ctx) + environments, err := project.List(ctx) if err != nil { lg. Fatal(). @@ -76,7 +76,7 @@ func CurrentEnvironmentState(ctx context.Context, workspace *state.Workspace) *s Fatal(). Err(err). Strs("environments", envNames). - Msg("multiple environments available in the workspace, select one with `--environment`") + Msg("multiple environments available in the project, select one with `--environment`") } return environments[0] diff --git a/cmd/dagger/cmd/common/track.go b/cmd/dagger/cmd/common/track.go index 30078487..885f3760 100644 --- a/cmd/dagger/cmd/common/track.go +++ b/cmd/dagger/cmd/common/track.go @@ -32,9 +32,9 @@ func commandName(cmd *cobra.Command) string { return strings.Join(parts, " ") } -// TrackWorkspaceCommand is like TrackCommand but includes workspace and +// TrackProjectCommand is like TrackCommand but includes project and // optionally environment metadata. -func TrackWorkspaceCommand(ctx context.Context, cmd *cobra.Command, w *state.Workspace, env *state.State, props ...*telemetry.Property) chan struct{} { +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 @@ -42,8 +42,8 @@ func TrackWorkspaceCommand(ctx context.Context, cmd *cobra.Command, w *state.Wor Value: hash(gitRepoURL(w.Path)), }, { - // The workspace path might contain the username (e.g. /home/user/workspace), so we hash itfor privacy. - Name: "workspace_path_hash", + // The project path might contain the username (e.g. /home/user/project), so we hash itfor privacy. + Name: "project_path_hash", Value: hash(w.Path), }, }, props...) diff --git a/cmd/dagger/cmd/edit.go b/cmd/dagger/cmd/edit.go index 768f2d4b..67481f80 100644 --- a/cmd/dagger/cmd/edit.go +++ b/cmd/dagger/cmd/edit.go @@ -34,14 +34,14 @@ var editCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", st.Name). Logger() - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st) + doneCh := common.TrackProjectCommand(ctx, cmd, project, st) data, err := yaml.Marshal(st) if err != nil { @@ -92,7 +92,7 @@ var editCmd = &cobra.Command{ lg.Fatal().Err(err).Str("environment", st.Name).Msg("invalid input") } - if err := workspace.Save(ctx, st); err != nil { + if err := project.Save(ctx, st); err != nil { lg.Fatal().Err(err).Msg("failed to save state") } }, diff --git a/cmd/dagger/cmd/init.go b/cmd/dagger/cmd/init.go index be8438a2..26f9eeda 100644 --- a/cmd/dagger/cmd/init.go +++ b/cmd/dagger/cmd/init.go @@ -12,7 +12,7 @@ import ( var initCmd = &cobra.Command{ Use: "init", - Short: "Initialize a new empty workspace", + Short: "Initialize a new empty project", Args: cobra.NoArgs, PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: @@ -25,7 +25,7 @@ var initCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - dir := viper.GetString("workspace") + dir := viper.GetString("project") if dir == "" { cwd, err := os.Getwd() if err != nil { @@ -37,12 +37,12 @@ var initCmd = &cobra.Command{ dir = cwd } - workspace, err := state.Init(ctx, dir) + project, err := state.Init(ctx, dir) if err != nil { - lg.Fatal().Err(err).Msg("failed to initialize workspace") + lg.Fatal().Err(err).Msg("failed to initialize project") } - <-common.TrackWorkspaceCommand(ctx, cmd, workspace, nil) + <-common.TrackProjectCommand(ctx, cmd, project, nil) }, } diff --git a/cmd/dagger/cmd/input/dir.go b/cmd/dagger/cmd/input/dir.go index a64f45d7..18b60799 100644 --- a/cmd/dagger/cmd/input/dir.go +++ b/cmd/dagger/cmd/input/dir.go @@ -37,11 +37,11 @@ var dirCmd = &cobra.Command{ lg.Fatal().Err(err).Str("path", args[1]).Msg("dir doesn't exists") } - workspace := common.CurrentWorkspace(ctx) - if !strings.HasPrefix(p, workspace.Path) { - lg.Fatal().Err(err).Str("path", args[1]).Msg("dir is outside the workspace") + project := common.CurrentProject(ctx) + if !strings.HasPrefix(p, project.Path) { + lg.Fatal().Err(err).Str("path", args[1]).Msg("dir is outside the project") } - p, err = filepath.Rel(workspace.Path, p) + p, err = filepath.Rel(project.Path, p) if err != nil { lg.Fatal().Err(err).Str("path", args[1]).Msg("unable to resolve path") } diff --git a/cmd/dagger/cmd/input/list.go b/cmd/dagger/cmd/input/list.go index c37983f6..8e876331 100644 --- a/cmd/dagger/cmd/input/list.go +++ b/cmd/dagger/cmd/input/list.go @@ -32,14 +32,14 @@ var listCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", st.Name). Logger() - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st) + doneCh := common.TrackProjectCommand(ctx, cmd, project, st) c := common.NewClient(ctx) err := c.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { diff --git a/cmd/dagger/cmd/input/root.go b/cmd/dagger/cmd/input/root.go index 8f691f3e..391f5321 100644 --- a/cmd/dagger/cmd/input/root.go +++ b/cmd/dagger/cmd/input/root.go @@ -40,14 +40,14 @@ func init() { func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target string, input state.Input) { lg := *log.Ctx(ctx) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", st.Name). Logger() - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st, &telemetry.Property{ + doneCh := common.TrackProjectCommand(ctx, cmd, project, st, &telemetry.Property{ Name: "input_target", Value: target, }) @@ -71,7 +71,7 @@ func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target stri lg.Fatal().Err(err).Msg("invalid input") } - if err := workspace.Save(ctx, st); err != nil { + if err := project.Save(ctx, st); err != nil { lg.Fatal().Err(err).Msg("cannot update environment") } } diff --git a/cmd/dagger/cmd/input/unset.go b/cmd/dagger/cmd/input/unset.go index b122d7f7..26287ba5 100644 --- a/cmd/dagger/cmd/input/unset.go +++ b/cmd/dagger/cmd/input/unset.go @@ -22,11 +22,11 @@ var unsetCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) st.RemoveInputs(args[0]) - if err := workspace.Save(ctx, st); err != nil { + if err := project.Save(ctx, st); err != nil { lg.Fatal().Err(err).Str("environment", st.Name).Msg("cannot update environment") } lg.Info().Str("environment", st.Name).Msg("updated environment") diff --git a/cmd/dagger/cmd/list.go b/cmd/dagger/cmd/list.go index c7224cd2..ac27b1f0 100644 --- a/cmd/dagger/cmd/list.go +++ b/cmd/dagger/cmd/list.go @@ -29,10 +29,10 @@ var listCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, nil) + project := common.CurrentProject(ctx) + doneCh := common.TrackProjectCommand(ctx, cmd, project, nil) - environments, err := workspace.List(ctx) + environments, err := project.List(ctx) if err != nil { lg. Fatal(). diff --git a/cmd/dagger/cmd/mod/file.go b/cmd/dagger/cmd/mod/file.go index 8ac5001a..4f36b8ef 100644 --- a/cmd/dagger/cmd/mod/file.go +++ b/cmd/dagger/cmd/mod/file.go @@ -24,11 +24,11 @@ const tmpBasePath = "./cue.mod/tmp" type file struct { require []*require - workspacePath string + projectPath string } -func readPath(workspacePath string) (*file, error) { - p := path.Join(workspacePath, filePath) +func readPath(projectPath string) (*file, error) { + p := path.Join(projectPath, filePath) f, err := os.Open(p) if err != nil { @@ -47,7 +47,7 @@ func readPath(workspacePath string) (*file, error) { return nil, err } - modFile.workspacePath = workspacePath + modFile.projectPath = projectPath return modFile, nil } @@ -102,7 +102,7 @@ func nonEmptyLines(b []byte) []string { func (f *file) processRequire(req *require, upgrade bool) (bool, error) { var isNew bool - tmpPath := path.Join(f.workspacePath, tmpBasePath, req.repo) + tmpPath := path.Join(f.projectPath, tmpBasePath, req.repo) if err := os.MkdirAll(tmpPath, 0755); err != nil { return false, fmt.Errorf("error creating tmp dir for cloning package") } @@ -117,7 +117,7 @@ func (f *file) processRequire(req *require, upgrade bool) (bool, error) { } existing := f.search(req) - destPath := path.Join(f.workspacePath, destBasePath) + destPath := path.Join(f.projectPath, destBasePath) // requirement is new, so we should move the files and add it to the mod file if existing == nil { @@ -167,7 +167,7 @@ func (f *file) processRequire(req *require, upgrade bool) (bool, error) { } func (f *file) write() error { - return ioutil.WriteFile(path.Join(f.workspacePath, filePath), f.contents().Bytes(), 0600) + return ioutil.WriteFile(path.Join(f.projectPath, filePath), f.contents().Bytes(), 0600) } func (f *file) contents() *bytes.Buffer { diff --git a/cmd/dagger/cmd/mod/get.go b/cmd/dagger/cmd/mod/get.go index 30638764..23b1e8a4 100644 --- a/cmd/dagger/cmd/mod/get.go +++ b/cmd/dagger/cmd/mod/get.go @@ -25,15 +25,15 @@ var getCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st, &telemetry.Property{ + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) + doneCh := common.TrackProjectCommand(ctx, cmd, project, st, &telemetry.Property{ Name: "packages", Value: args, }) // read mod file in the current dir - modFile, err := readPath(workspace.Path) + modFile, err := readPath(project.Path) if err != nil { lg.Fatal().Err(err).Msg("error loading module file") } diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index a86cb6f5..3ab0b6b3 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -23,7 +23,7 @@ var newCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) + project := common.CurrentProject(ctx) if viper.GetString("environment") != "" { lg. @@ -32,7 +32,7 @@ var newCmd = &cobra.Command{ } name := args[0] - st, err := workspace.Create(ctx, name, state.Plan{ + st, err := project.Create(ctx, name, state.Plan{ Package: viper.GetString("package"), }) @@ -40,7 +40,7 @@ var newCmd = &cobra.Command{ lg.Fatal().Err(err).Msg("failed to create environment") } - <-common.TrackWorkspaceCommand(ctx, cmd, workspace, st) + <-common.TrackProjectCommand(ctx, cmd, project, st) }, } diff --git a/cmd/dagger/cmd/output/list.go b/cmd/dagger/cmd/output/list.go index d594a1b0..1567a854 100644 --- a/cmd/dagger/cmd/output/list.go +++ b/cmd/dagger/cmd/output/list.go @@ -31,14 +31,14 @@ var listCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", st.Name). Logger() - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st) + doneCh := common.TrackProjectCommand(ctx, cmd, project, st) cl := common.NewClient(ctx) err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { diff --git a/cmd/dagger/cmd/query.go b/cmd/dagger/cmd/query.go index 3a0b8223..522734b8 100644 --- a/cmd/dagger/cmd/query.go +++ b/cmd/dagger/cmd/query.go @@ -27,8 +27,8 @@ var queryCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - state := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + state := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", state.Name). @@ -40,7 +40,7 @@ var queryCmd = &cobra.Command{ cuePath = cue.ParsePath(args[0]) } - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, state) + doneCh := common.TrackProjectCommand(ctx, cmd, project, state) cueVal := compiler.NewValue() diff --git a/cmd/dagger/cmd/root.go b/cmd/dagger/cmd/root.go index bcc322cf..901ae0df 100644 --- a/cmd/dagger/cmd/root.go +++ b/cmd/dagger/cmd/root.go @@ -34,7 +34,7 @@ func init() { "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)") rootCmd.PersistentFlags().StringP("environment", "e", "", "Select an environment") - rootCmd.PersistentFlags().StringP("workspace", "w", "", "Specify a workspace (defaults to current git repository)") + rootCmd.PersistentFlags().String("project", "", "Specify a project directory (defaults to current)") rootCmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) { lg := logger.New() diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index d528de31..bd59c9ae 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -34,14 +34,14 @@ var upCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) - workspace := common.CurrentWorkspace(ctx) - st := common.CurrentEnvironmentState(ctx, workspace) + project := common.CurrentProject(ctx) + st := common.CurrentEnvironmentState(ctx, project) lg = lg.With(). Str("environment", st.Name). Logger() - doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st) + doneCh := common.TrackProjectCommand(ctx, cmd, project, st) cl := common.NewClient(ctx) @@ -56,7 +56,7 @@ var upCmd = &cobra.Command{ } st.Computed = env.Computed().JSON().PrettyString() - if err := workspace.Save(ctx, st); err != nil { + if err := project.Save(ctx, st); err != nil { return err } diff --git a/state/input.go b/state/input.go index d4525dde..1b074d28 100644 --- a/state/input.go +++ b/state/input.go @@ -108,10 +108,10 @@ func (dir dirInput) Compile(_ string, state *State) (*compiler.Value, error) { p := dir.Path if !filepath.IsAbs(p) { - p = filepath.Clean(path.Join(state.Workspace, dir.Path)) + p = filepath.Clean(path.Join(state.Project, dir.Path)) } - if !strings.HasPrefix(p, state.Workspace) { - return nil, fmt.Errorf("%q is outside the workspace", dir.Path) + if !strings.HasPrefix(p, state.Project) { + return nil, fmt.Errorf("%q is outside the project", dir.Path) } llb := fmt.Sprintf( diff --git a/state/workspace.go b/state/project.go similarity index 90% rename from state/workspace.go rename to state/project.go index dacfddea..89bf52ff 100644 --- a/state/workspace.go +++ b/state/project.go @@ -32,11 +32,11 @@ const ( computedFile = "computed.json" ) -type Workspace struct { +type Project struct { Path string } -func Init(ctx context.Context, dir string) (*Workspace, error) { +func Init(ctx context.Context, dir string) (*Project, error) { root, err := filepath.Abs(dir) if err != nil { return nil, err @@ -57,12 +57,12 @@ func Init(ctx context.Context, dir string) (*Workspace, error) { return nil, err } - return &Workspace{ + return &Project{ Path: root, }, nil } -func Open(ctx context.Context, dir string) (*Workspace, error) { +func Open(ctx context.Context, dir string) (*Project, error) { _, err := os.Stat(path.Join(dir, daggerDir)) if err != nil { if errors.Is(err, os.ErrNotExist) { @@ -76,12 +76,12 @@ func Open(ctx context.Context, dir string) (*Workspace, error) { return nil, err } - return &Workspace{ + return &Project{ Path: root, }, nil } -func Current(ctx context.Context) (*Workspace, error) { +func Current(ctx context.Context) (*Project, error) { current, err := os.Getwd() if err != nil { return nil, err @@ -103,11 +103,11 @@ func Current(ctx context.Context) (*Workspace, error) { return nil, ErrNotInit } -func (w *Workspace) envPath(name string) string { +func (w *Project) envPath(name string) string { return path.Join(w.Path, daggerDir, envDir, name) } -func (w *Workspace) List(ctx context.Context) ([]*State, error) { +func (w *Project) List(ctx context.Context) ([]*State, error) { var ( environments = []*State{} err error @@ -139,7 +139,7 @@ func (w *Workspace) List(ctx context.Context) ([]*State, error) { return environments, nil } -func (w *Workspace) Get(ctx context.Context, name string) (*State, error) { +func (w *Project) Get(ctx context.Context, name string) (*State, error) { envPath, err := filepath.Abs(w.envPath(name)) if err != nil { return nil, err @@ -179,7 +179,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) { st.Plan.Module = planRelPath } } - st.Workspace = w.Path + st.Project = w.Path computed, err := os.ReadFile(path.Join(envPath, stateDir, computedFile)) if err == nil { @@ -189,7 +189,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) { return &st, nil } -func (w *Workspace) Save(ctx context.Context, st *State) error { +func (w *Project) Save(ctx context.Context, st *State) error { data, err := yaml.Marshal(st) if err != nil { return err @@ -234,7 +234,7 @@ func (w *Workspace) Save(ctx context.Context, st *State) error { return nil } -func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State, error) { +func (w *Project) Create(ctx context.Context, name string, plan Plan) (*State, error) { if _, err := w.Get(ctx, name); err == nil { return nil, ErrExist } @@ -257,8 +257,8 @@ func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State, manifestPath := path.Join(envPath, manifestFile) st := &State{ - Path: envPath, - Workspace: w.Path, + Path: envPath, + Project: w.Path, Plan: Plan{ Package: pkg, }, @@ -293,7 +293,7 @@ func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State, return st, nil } -func (w *Workspace) cleanPackageName(ctx context.Context, pkg string) (string, error) { +func (w *Project) cleanPackageName(ctx context.Context, pkg string) (string, error) { lg := log. Ctx(ctx). With(). @@ -325,7 +325,7 @@ func (w *Workspace) cleanPackageName(ctx context.Context, pkg string) (string, e } if !strings.HasPrefix(p, w.Path) { - lg.Fatal().Err(err).Msg("package is outside the workspace") + lg.Fatal().Err(err).Msg("package is outside the project") return "", err } diff --git a/state/workspace_test.go b/state/project_test.go similarity index 75% rename from state/workspace_test.go rename to state/project_test.go index 28b86810..137a3333 100644 --- a/state/workspace_test.go +++ b/state/project_test.go @@ -12,7 +12,7 @@ import ( "gopkg.in/yaml.v3" ) -func TestWorkspace(t *testing.T) { +func TestProject(t *testing.T) { ctx := context.TODO() keychain.EnsureDefaultKey(ctx) @@ -25,39 +25,39 @@ func TestWorkspace(t *testing.T) { require.ErrorIs(t, ErrNotInit, err) // Init - workspace, err := Init(ctx, root) + project, err := Init(ctx, root) require.NoError(t, err) - require.Equal(t, root, workspace.Path) + require.Equal(t, root, project.Path) // Create - st, err := workspace.Create(ctx, "test", Plan{ + st, err := project.Create(ctx, "test", Plan{ Module: ".", }) require.NoError(t, err) require.Equal(t, "test", st.Name) // Open - workspace, err = Open(ctx, root) + project, err = Open(ctx, root) require.NoError(t, err) - require.Equal(t, root, workspace.Path) + require.Equal(t, root, project.Path) // List - envs, err := workspace.List(ctx) + envs, err := project.List(ctx) require.NoError(t, err) require.Len(t, envs, 1) require.Equal(t, "test", envs[0].Name) // Get - env, err := workspace.Get(ctx, "test") + env, err := project.Get(ctx, "test") require.NoError(t, err) require.Equal(t, "test", env.Name) // Save require.NoError(t, env.SetInput("foo", TextInput("bar"))) - require.NoError(t, workspace.Save(ctx, env)) - workspace, err = Open(ctx, root) + require.NoError(t, project.Save(ctx, env)) + project, err = Open(ctx, root) require.NoError(t, err) - env, err = workspace.Get(ctx, "test") + env, err = project.Get(ctx, "test") require.NoError(t, err) require.Contains(t, env.Inputs, "foo") } @@ -77,28 +77,28 @@ func TestEncryption(t *testing.T) { root, err := os.MkdirTemp(os.TempDir(), "dagger-*") require.NoError(t, err) - workspace, err := Init(ctx, root) + project, err := Init(ctx, root) require.NoError(t, err) - _, err = workspace.Create(ctx, "test", Plan{ + _, err = project.Create(ctx, "test", Plan{ Module: ".", }) require.NoError(t, err) // Set a plaintext input, make sure it is not encrypted - st, err := workspace.Get(ctx, "test") + st, err := project.Get(ctx, "test") require.NoError(t, err) require.NoError(t, st.SetInput("plain", TextInput("plain"))) - require.NoError(t, workspace.Save(ctx, st)) + require.NoError(t, project.Save(ctx, st)) o := readManifest(st) require.Contains(t, o.Inputs, "plain") require.Equal(t, "plain", string(*o.Inputs["plain"].Text)) // Set a secret input, make sure it's encrypted - st, err = workspace.Get(ctx, "test") + st, err = project.Get(ctx, "test") require.NoError(t, err) require.NoError(t, st.SetInput("secret", SecretInput("secret"))) - require.NoError(t, workspace.Save(ctx, st)) + require.NoError(t, project.Save(ctx, st)) o = readManifest(st) require.Contains(t, o.Inputs, "secret") secretValue := string(*o.Inputs["secret"].Secret) @@ -106,10 +106,10 @@ func TestEncryption(t *testing.T) { require.True(t, strings.HasPrefix(secretValue, "ENC[")) // Change another input, make sure our secret didn't change - st, err = workspace.Get(ctx, "test") + st, err = project.Get(ctx, "test") require.NoError(t, err) require.NoError(t, st.SetInput("plain", TextInput("different"))) - require.NoError(t, workspace.Save(ctx, st)) + require.NoError(t, project.Save(ctx, st)) o = readManifest(st) require.Contains(t, o.Inputs, "plain") require.Equal(t, "different", string(*o.Inputs["plain"].Text)) diff --git a/state/state.go b/state/state.go index 0bf0bd2f..918d19bb 100644 --- a/state/state.go +++ b/state/state.go @@ -13,8 +13,8 @@ type State struct { // State path Path string `yaml:"-"` - // Workspace path - Workspace string `yaml:"-"` + // Project path + Project string `yaml:"-"` // Plan Plan Plan `yaml:"plan,omitempty"` @@ -33,7 +33,7 @@ type State struct { // Cue module containing the environment plan func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) { - w := s.Workspace + w := s.Project // FIXME: backward compatibility if mod := s.Plan.Module; mod != "" { w = path.Join(w, mod) @@ -44,7 +44,7 @@ func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) { // However: // 1) As of right now, there's no way to update universe through the // CLI, so we are lazily updating on `dagger up` using the embedded `universe` - // 2) For backward compatibility: if the workspace was `dagger + // 2) For backward compatibility: if the project was `dagger // init`-ed before we added support for vendoring universe, it might not // contain a `cue.mod`. if err := vendorUniverse(ctx, w); err != nil { @@ -83,11 +83,11 @@ func (s *State) CompileInputs() (*compiler.Value, error) { // VendorUniverse vendors the latest (built-in) version of the universe into the // environment's `cue.mod`. -// FIXME: This has nothing to do in `State` and should be tied to a `Workspace`. +// FIXME: This has nothing to do in `State` and should be tied to a `Project`. // However, since environments could point to different modules before, we have // to handle vendoring on a per environment basis. func (s *State) VendorUniverse(ctx context.Context) error { - w := s.Workspace + w := s.Project // FIXME: backward compatibility if mod := s.Plan.Module; mod != "" { w = path.Join(w, mod)