Skip to content
Merged
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
42 changes: 42 additions & 0 deletions pkg/cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

package cmd

import (
"github.com/spf13/cobra"
)

func NewListCmd() *cobra.Command {
// Create the workspace list command
workspaceListCmd := NewWorkspaceListCmd()

// Create an alias command that delegates to workspace list
cmd := &cobra.Command{
Use: "list",
Short: workspaceListCmd.Short,
Long: workspaceListCmd.Long,
PreRunE: workspaceListCmd.PreRunE,
RunE: workspaceListCmd.RunE,
}

// Copy flags from workspace list command
cmd.Flags().AddFlagSet(workspaceListCmd.Flags())

return cmd
}
42 changes: 42 additions & 0 deletions pkg/cmd/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

package cmd

import (
"testing"
)

func TestListCmd(t *testing.T) {
t.Parallel()

cmd := NewListCmd()
if cmd == nil {
t.Fatal("NewListCmd() returned nil")
}

if cmd.Use != "list" {
t.Errorf("Expected Use to be 'list', got '%s'", cmd.Use)
}

// Verify it has the same behavior as workspace list
workspaceListCmd := NewWorkspaceListCmd()
if cmd.Short != workspaceListCmd.Short {
t.Errorf("Expected Short to match workspace list, got '%s'", cmd.Short)
}
}
2 changes: 2 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewRootCmd() *cobra.Command {
// Add subcommands
rootCmd.AddCommand(NewVersionCmd())
rootCmd.AddCommand(NewInitCmd())
rootCmd.AddCommand(NewWorkspaceCmd())
rootCmd.AddCommand(NewListCmd())

// Global flags
rootCmd.PersistentFlags().String("storage", defaultStoragePath, "Directory where kortex-cli will store all its files")
Expand Down
36 changes: 36 additions & 0 deletions pkg/cmd/workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

package cmd

import (
"github.com/spf13/cobra"
)

func NewWorkspaceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "workspace",
Short: "Manage workspaces",
Long: "Manage workspaces registered with kortex-cli init",
}

// Add subcommands
cmd.AddCommand(NewWorkspaceListCmd())

return cmd
}
89 changes: 89 additions & 0 deletions pkg/cmd/workspace_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**********************************************************************
* Copyright (C) 2026 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

package cmd

import (
"fmt"

"github.com/kortex-hub/kortex-cli/pkg/instances"
"github.com/spf13/cobra"
)

// workspaceListCmd contains the configuration for the workspace list command
type workspaceListCmd struct {
manager instances.Manager
}

// preRun validates the parameters and flags
func (w *workspaceListCmd) preRun(cmd *cobra.Command, args []string) error {
// Get storage directory from global flag
storageDir, err := cmd.Flags().GetString("storage")
if err != nil {
return fmt.Errorf("failed to read --storage flag: %w", err)
}

// Create manager
manager, err := instances.NewManager(storageDir)
if err != nil {
return fmt.Errorf("failed to create manager: %w", err)
}
w.manager = manager

return nil
}

// run executes the workspace list command logic
func (w *workspaceListCmd) run(cmd *cobra.Command, args []string) error {
// Get all instances
instancesList, err := w.manager.List()
if err != nil {
return fmt.Errorf("failed to list instances: %w", err)
}

// Display the instances
if len(instancesList) == 0 {
cmd.Println("No workspaces registered")
return nil
}

for _, instance := range instancesList {
cmd.Printf("ID: %s\n", instance.GetID())
cmd.Printf(" Sources: %s\n", instance.GetSourceDir())
cmd.Printf(" Configuration: %s\n", instance.GetConfigDir())
cmd.Println()
}

return nil
}

func NewWorkspaceListCmd() *cobra.Command {
c := &workspaceListCmd{}

cmd := &cobra.Command{
Use: "list",
Short: "List all registered workspaces",
Long: "List all workspaces registered with kortex-cli init",
PreRunE: c.preRun,
RunE: c.run,
}

// TODO: Add flags as needed

return cmd
}
Loading