Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/cloudx/client/command_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type (
projectID, workspaceID uuid.UUID
configLocation string
noConfirm, isQuiet bool
workspaceFromConfig bool
VerboseErrWriter io.Writer
Stdin *bufio.Reader
openBrowserHook func(string) error
Expand Down Expand Up @@ -231,6 +232,7 @@ func (h *CommandHelper) determineWorkspaceID(ctx context.Context, config *Config
workspace = ws
} else if config.SelectedWorkspace != uuid.Nil {
h.workspaceID = config.SelectedWorkspace
h.workspaceFromConfig = true
return nil
}
workspace = strings.TrimSpace(workspace)
Expand Down Expand Up @@ -261,9 +263,11 @@ func (h *CommandHelper) determineProjectID(ctx context.Context, config *Config)
if h.projectOverride != nil {
return fmt.Errorf("project API key is set but project flag is also set, please remove one")
}
if h.workspaceID != uuid.Nil {
if h.workspaceID != uuid.Nil && !h.workspaceFromConfig {
return fmt.Errorf("project API key is set but workspace is also set, please remove one")
}
// Clear workspace from config since project API key takes precedence.
h.workspaceID = uuid.Nil
pjs, err := h.ListProjects(ctx, nil)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloudx/client/command_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func TestCommandHelper(t *testing.T) {
assert.Equal(t, tc.project.Id, actual.Id)
assertValidProject(t, tc.project)

actual, err = authenticated.GetProject(ctx, tc.project.Slug[0:4], tc.project.WorkspaceId.Get())
actual, err = authenticated.GetProject(ctx, tc.project.Slug[:len(tc.project.Slug)-1], tc.project.WorkspaceId.Get())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests whether we can fetch by a slug prefix, but the updated test is just the full slug?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, haha. Claude identified this as a flake when truncated slugs where conflicting.

Good catch.

require.NoError(t, err)
assert.Equal(t, tc.project.Id, actual.Id)
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloudx/relationtuples/relationtuples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestCRUD(t *testing.T) {
func createLegacyNamespace(t *testing.T, project, rawNamespace string) {
t.Helper()
_, _, err := defaultCmd.Exec(nil, "patch", "permission-config", "--project", project,
"--add", `/namespaces/-=`+rawNamespace)
"--replace", `/namespaces=[`+rawNamespace+`]`)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"os"
"sync"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -19,8 +18,6 @@ import (
"github.com/ory/x/cmdx"
)

var commandTemplatingOnce sync.Once

func NewRootCmd() *cobra.Command {
c := &cobra.Command{
Use: "ory",
Expand Down Expand Up @@ -51,9 +48,7 @@ func NewRootCmd() *cobra.Command {
cloudx.NewIsCmd(),
versionCmd,
)
commandTemplatingOnce.Do(func() {
cmdx.EnableUsageTemplating(c)
})
cmdx.EnableUsageTemplating(c)

return c
}
Expand Down
Loading