Skip to content
Snippets Groups Projects
Commit 9fc121fe authored by Alex Clemmer's avatar Alex Clemmer Committed by GitHub
Browse files

Merge pull request #151 from hausdorff/proto-list

Add `prototype list` command
parents e21a8e17 f70428dd
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ import (
func init() {
RootCmd.AddCommand(prototypeCmd)
prototypeCmd.AddCommand(prototypeListCmd)
prototypeCmd.AddCommand(prototypeDescribeCmd)
prototypeCmd.AddCommand(prototypeSearchCmd)
prototypeCmd.AddCommand(prototypeUseCmd)
......@@ -77,6 +78,29 @@ Commands:
ksonnet prototype search deployment`,
}
var prototypeListCmd = &cobra.Command{
Use: "list <name-substring>",
Short: `List all known ksonnet prototypes`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("Command 'prototype list' does not take any arguments")
}
index := prototype.NewIndex([]*prototype.SpecificationSchema{})
protos, err := index.List()
if err != nil {
return err
} else if len(protos) == 0 {
return fmt.Errorf("No prototypes found")
}
fmt.Print(protos)
return nil
},
Long: `List all known ksonnet prototypes.`,
}
var prototypeDescribeCmd = &cobra.Command{
Use: "describe <prototype-name>",
Short: `Describe a ksonnet prototype`,
......
......@@ -13,6 +13,14 @@ type index struct {
prototypes map[string]*SpecificationSchema
}
func (idx *index) List() (SpecificationSchemas, error) {
prototypes := []*SpecificationSchema{}
for _, prototype := range idx.prototypes {
prototypes = append(prototypes, prototype)
}
return prototypes, nil
}
func (idx *index) SearchNames(query string, opts SearchOptions) (SpecificationSchemas, error) {
// TODO(hausdorff): This is the world's worst search algorithm. Improve it at
// some point.
......
......@@ -31,6 +31,7 @@ const (
// Index represents a queryable index of prototype specifications.
type Index interface {
List() (SpecificationSchemas, error)
SearchNames(query string, opts SearchOptions) (SpecificationSchemas, error)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment