This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
22b5c39
commit b571fb4
Showing
6 changed files
with
107 additions
and
6 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,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type ClientGetDataset struct { | ||
Client | ||
} | ||
|
||
func (s *ClientGetDataset) Customize(cmd *cobra.Command) { | ||
cmd.Use = "get-dataset <dataset-id>" | ||
cmd.Short = "Get a dataset" | ||
cmd.Args = cobra.ExactArgs(1) | ||
} | ||
|
||
func (s *ClientGetDataset) Run(cmd *cobra.Command, args []string) error { | ||
c, err := s.getClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
datasetID := args[0] | ||
|
||
ds, err := c.GetDataset(cmd.Context(), datasetID) | ||
if err != nil { | ||
return fmt.Errorf("failed to get dataset: %w", err) | ||
} | ||
|
||
if ds == nil { | ||
fmt.Println("dataset not found") | ||
return fmt.Errorf("dataset not found") | ||
} | ||
|
||
jsonOutput, err := json.Marshal(ds) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal dataset: %w", err) | ||
} | ||
|
||
fmt.Println(string(jsonOutput)) | ||
return nil | ||
} |
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,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type ClientListDatasets struct { | ||
Client | ||
} | ||
|
||
func (s *ClientListDatasets) Customize(cmd *cobra.Command) { | ||
cmd.Use = "list-datasets" | ||
cmd.Short = "List existing datasets" | ||
cmd.Args = cobra.NoArgs | ||
} | ||
|
||
func (s *ClientListDatasets) Run(cmd *cobra.Command, args []string) error { | ||
c, err := s.getClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ds, err := c.ListDatasets(cmd.Context()) | ||
if err != nil { | ||
return fmt.Errorf("failed to list datasets: %w", err) | ||
} | ||
|
||
if len(ds) == 0 { | ||
fmt.Println("no datasets found") | ||
return nil | ||
} | ||
|
||
jsonOutput, err := json.Marshal(ds) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal datasets: %w", err) | ||
} | ||
|
||
fmt.Println(string(jsonOutput)) | ||
return nil | ||
} |
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,8 @@ | ||
package datastore | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// ErrDBDocumentNotFound is returned when a document is not found in the database. | ||
var ErrDBDocumentNotFound = errors.New("document not found in database") |