-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
311 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rockset/cli/completion" | ||
"github.com/rockset/cli/config" | ||
"github.com/rockset/cli/format" | ||
"github.com/rockset/cli/lookup" | ||
"github.com/rockset/cli/sort" | ||
"github.com/rockset/rockset-go-client/openapi" | ||
"github.com/spf13/cobra" | ||
"strings" | ||
) | ||
|
||
func NewListMountsCmd() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "mounts [NAME | ID]", | ||
Aliases: []string{"m", "mount"}, | ||
Args: cobra.ExactArgs(1), | ||
Short: "list collection mounts for a virtual instance", | ||
Annotations: group("mount"), | ||
ValidArgsFunction: completion.VirtualInstance(Version), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
rs, err := config.Client(cmd, Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id, err := lookup.VirtualInstanceNameOrIDtoID(ctx, rs, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mounts, err := rs.ListCollectionMounts(ctx, id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ms := sort.Multi[openapi.CollectionMount]{ | ||
LessFuncs: []func(p1 *openapi.CollectionMount, p2 *openapi.CollectionMount) bool{ | ||
sort.ByCollectionPath[*openapi.CollectionMount], | ||
}, | ||
} | ||
ms.Sort(mounts) | ||
|
||
return formatList(cmd, format.ToInterfaceArray(mounts)) | ||
}, | ||
} | ||
|
||
return &cmd | ||
} | ||
|
||
func NewGetMountCmd() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "mount PATH", | ||
Aliases: []string{"m"}, | ||
Args: cobra.ExactArgs(1), | ||
Short: "get collection mount information", | ||
Annotations: group("mount"), | ||
ValidArgsFunction: completion.CollectionMount(Version), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
rs, err := config.Client(cmd, Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vi, _ := cmd.Flags().GetString("vi") | ||
id, err := lookup.VirtualInstanceNameOrIDtoID(ctx, rs, vi) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mount, err := rs.GetCollectionMount(ctx, id, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return formatOne(cmd, mount) | ||
}, | ||
} | ||
|
||
cmd.Flags().String("vi", "", "virtual instance id or name") | ||
cmd.MarkFlagRequired("vi") | ||
_ = cmd.RegisterFlagCompletionFunc("vi", completion.VirtualInstance(Version)) | ||
|
||
return &cmd | ||
} | ||
|
||
func NewMountCollectionsCmd() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "mount PATH", | ||
Aliases: []string{"m"}, | ||
Args: cobra.MinimumNArgs(1), | ||
Short: "mount one or more collections on a virtual instance", | ||
Annotations: group("mount"), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
rs, err := config.Client(cmd, Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vi, _ := cmd.Flags().GetString("vi") | ||
id, err := lookup.VirtualInstanceNameOrIDtoID(ctx, rs, vi) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mounts, err := rs.MountCollections(ctx, id, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var mounted = make([]string, len(mounts)) | ||
for i, mount := range mounts { | ||
mounted[i] = mount.GetCollectionPath() | ||
} | ||
|
||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "mounted %s on %s\n", strings.Join(mounted, ", "), vi) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().String("vi", "", "virtual instance id or name") | ||
cmd.MarkFlagRequired("vi") | ||
_ = cmd.RegisterFlagCompletionFunc("vi", completion.VirtualInstance(Version)) | ||
|
||
return &cmd | ||
} | ||
|
||
func NewUnmountCollectionCmd() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "unmount PATH", | ||
Aliases: []string{"m"}, | ||
Args: cobra.MinimumNArgs(1), | ||
Short: "unmount a collection from a virtual instance", | ||
Annotations: group("mount"), | ||
ValidArgsFunction: completion.CollectionMount(Version), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
rs, err := config.Client(cmd, Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vi, _ := cmd.Flags().GetString("vi") | ||
id, err := lookup.VirtualInstanceNameOrIDtoID(ctx, rs, vi) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mount, err := rs.UnmountCollection(ctx, id, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "unmounted %s from %s\n", mount.GetCollectionPath(), vi) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().String("vi", "", "virtual instance id or name") | ||
cmd.MarkFlagRequired("vi") | ||
_ = cmd.RegisterFlagCompletionFunc("vi", completion.VirtualInstance(Version)) | ||
|
||
return &cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package format | ||
|
||
import "github.com/rockset/rockset-go-client/openapi" | ||
|
||
var MountDefaultSelector = DefaultSelector{ | ||
Normal: []FieldSelection{ | ||
NewFieldSelection("Collection Path", "collection_path"), | ||
NewFieldSelection("State", "state"), | ||
{ | ||
ColumnName: "Last Queried", | ||
Path: []PathElem{{FieldName: "stats"}, {FieldName: "last_queried_ms"}}, | ||
FieldFormatter: TimeSinceFormatter{}, | ||
}, | ||
}, | ||
Wide: []FieldSelection{ | ||
NewFieldSelection("Collection Path", "collection_path"), | ||
NewFieldSelection("ID", "id"), | ||
NewFieldSelection("State", "state"), | ||
{ | ||
ColumnName: "Last Queried", | ||
Path: []PathElem{{FieldName: "stats"}, {FieldName: "last_queried_ms"}}, | ||
FieldFormatter: TimeSinceFormatter{}, | ||
}, | ||
NewFieldSelection("Virtual Instance ID", "virtual_instance_id"), | ||
}, | ||
} | ||
|
||
var _ = openapi.CollectionMount{ | ||
CollectionPath: nil, | ||
CreatedAt: nil, | ||
Id: nil, | ||
LastRefreshTimeMillis: nil, | ||
Rrn: nil, | ||
SnapshotExpirationTimeMillis: nil, | ||
State: nil, | ||
Stats: &openapi.CollectionMountStats{ | ||
LastQueriedMs: nil, | ||
}, | ||
VirtualInstanceId: nil, | ||
VirtualInstanceRrn: nil, | ||
} |
Oops, something went wrong.