|
7 | 7 | "github.com/ActiveState/cli/internal/errs" |
8 | 8 | "github.com/ActiveState/cli/internal/locale" |
9 | 9 | "github.com/ActiveState/cli/internal/logging" |
| 10 | + "github.com/ActiveState/cli/internal/osutils" |
10 | 11 | "github.com/ActiveState/cli/internal/prompt" |
11 | 12 | "github.com/ActiveState/cli/pkg/project" |
12 | 13 | "github.com/ActiveState/cli/pkg/projectfile" |
@@ -52,10 +53,19 @@ func FromPath(path string, ns *project.Namespaced) (*project.Project, error) { |
52 | 53 | return pj, nil |
53 | 54 | } |
54 | 55 |
|
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). |
56 | 58 | // This is primarily used by `state use` in order to fetch a project to switch to if it already |
57 | 59 | // exists locally. The namespace may omit the owner. |
58 | 60 | 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 | + |
59 | 69 | matchingProjects := make(map[string][]string) |
60 | 70 | matchingNamespaces := make([]string, 0) |
61 | 71 | for namespace, paths := range projectfile.GetProjectMapping(cfg) { |
|
0 commit comments