Skip to content

Commit 9422802

Browse files
committed
Merge branch version/0-35-0-RC1 to adopt changes from PR #2112
2 parents ff59b35 + be45f3f commit 9422802

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

cmd/state/internal/cmdtree/use.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func newUseCommand(prime *primer.Values) *captain.Command {
2323
{
2424
Name: locale.T("arg_state_use_namespace"),
2525
Description: locale.T("arg_state_use_namespace_description"),
26-
Required: true,
2726
Value: params.Namespace,
2827
},
2928
},

internal/runbits/findproject/project.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ActiveState/cli/internal/errs"
88
"github.com/ActiveState/cli/internal/locale"
99
"github.com/ActiveState/cli/internal/logging"
10+
"github.com/ActiveState/cli/internal/osutils"
1011
"github.com/ActiveState/cli/internal/prompt"
1112
"github.com/ActiveState/cli/pkg/project"
1213
"github.com/ActiveState/cli/pkg/projectfile"
@@ -52,10 +53,19 @@ func FromPath(path string, ns *project.Namespaced) (*project.Project, error) {
5253
return pj, nil
5354
}
5455

55-
// FromNamespaceLocal returns a local project (if any) that matches the given namespace.
56+
// FromNamespaceLocal returns a local project (if any) that matches the given namespace (or the
57+
// project in the current working directory if namespace was not given).
5658
// This is primarily used by `state use` in order to fetch a project to switch to if it already
5759
// exists locally. The namespace may omit the owner.
5860
func FromNamespaceLocal(ns *project.Namespaced, cfg projectfile.ConfigGetter, prompt prompt.Prompter) (*project.Project, error) {
61+
if ns == nil || !ns.IsValid() {
62+
root, err := osutils.Getwd()
63+
if err != nil {
64+
return nil, locale.WrapInputError(err, "Unable to determine current working directory. Please specify a project to use.")
65+
}
66+
return project.FromPath(root)
67+
}
68+
5969
matchingProjects := make(map[string][]string)
6070
matchingNamespaces := make([]string, 0)
6171
for namespace, paths := range projectfile.GetProjectMapping(cfg) {

test/integration/use_int_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ func (suite *UseIntegrationTestSuite) TestUse() {
105105
cp.ExpectExitCode(1)
106106
}
107107

108+
func (suite *UseIntegrationTestSuite) TestUseCwd() {
109+
suite.OnlyRunForTags(tagsuite.Use)
110+
111+
ts := e2e.New(suite.T(), false)
112+
defer ts.Close()
113+
114+
pythonDir := filepath.Join(ts.Dirs.Work, "MyPython3")
115+
116+
cp := ts.SpawnWithOpts(
117+
e2e.WithArgs("checkout", "ActiveState-CLI/Python3", pythonDir),
118+
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
119+
)
120+
cp.Expect("Checked out project")
121+
cp.ExpectExitCode(0)
122+
123+
cp = ts.SpawnWithOpts(
124+
e2e.WithArgs("use"),
125+
e2e.WithWorkDirectory(pythonDir),
126+
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
127+
)
128+
cp.Expect("Switched to project")
129+
cp.ExpectExitCode(0)
130+
131+
emptyDir := filepath.Join(ts.Dirs.Work, "EmptyDir")
132+
suite.Require().NoError(fileutils.Mkdir(emptyDir))
133+
cp = ts.SpawnWithOpts(
134+
e2e.WithArgs("use"),
135+
e2e.WithWorkDirectory(emptyDir),
136+
)
137+
cp.Expect("Unable to use project")
138+
cp.ExpectExitCode(1)
139+
}
140+
108141
func (suite *UseIntegrationTestSuite) TestReset() {
109142
suite.OnlyRunForTags(tagsuite.Use)
110143

0 commit comments

Comments
 (0)