diff --git a/commands/store_deploy.go b/commands/store_deploy.go index 54b78ffe..737a12c4 100644 --- a/commands/store_deploy.go +++ b/commands/store_deploy.go @@ -17,7 +17,6 @@ import ( func init() { // Setup flags that are used by multiple commands (variables defined in faas.go) storeDeployCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL starting with http(s)://") - storeDeployCmd.Flags().StringVar(&network, "network", "", "Name of the network") storeDeployCmd.Flags().StringVar(&functionName, "name", "", "Name of the deployed function (overriding name from the store)") storeDeployCmd.Flags().StringVarP(&functionNamespace, "namespace", "n", "", "Namespace of the function") // Setup flags that are used only by deploy command (variables defined above) @@ -42,7 +41,6 @@ var storeDeployCmd = &cobra.Command{ Use: `deploy (FUNCTION_NAME|FUNCTION_TITLE) [--name FUNCTION_NAME] [--gateway GATEWAY_URL] - [--network NETWORK_NAME] [--env ENVVAR=VALUE ...] [--label LABEL=VALUE ...] [--annotation ANNOTATION=VALUE ...] @@ -117,11 +115,6 @@ func runStoreDeploy(cmd *cobra.Command, args []string) error { } } - // Use the network from manifest if not changed by user - if !cmd.Flag("network").Changed { - network = item.Network - } - itemName := item.Name if functionName != "" { diff --git a/commands/store_describe.go b/commands/store_describe.go index d51a3411..64021961 100644 --- a/commands/store_describe.go +++ b/commands/store_describe.go @@ -8,22 +8,21 @@ import ( "fmt" "text/tabwriter" + "github.com/mitchellh/go-wordwrap" storeV2 "github.com/openfaas/faas-cli/schema/store/v2" "github.com/spf13/cobra" ) func init() { - // Setup flags used by store command - storeDescribeCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output for the field values") - storeCmd.AddCommand(storeDescribeCmd) } var storeDescribeCmd = &cobra.Command{ Use: `describe (FUNCTION_NAME|FUNCTION_TITLE) [--url STORE_URL]`, Short: "Show details of OpenFaaS function from a store", - Example: ` faas-cli store describe NodeInfo - faas-cli store describe NodeInfo --url https://host:port/store.json`, + Example: ` faas-cli store describe nodeinfo + faas-cli store describe nodeinfo --url https://host:port/store.json +`, Aliases: []string{"inspect"}, RunE: runStoreDescribe, } @@ -47,35 +46,52 @@ func runStoreDescribe(cmd *cobra.Command, args []string) error { return fmt.Errorf("function '%s' not found for platform '%s'", functionName, targetPlatform) } - verbose, err := cmd.Flags().GetBool("verbose") - if err != nil { - return err - } - - content := storeRenderItem(item, targetPlatform, verbose) + content := storeRenderItem(item, targetPlatform) fmt.Print(content) return nil } -func storeRenderItem(item *storeV2.StoreFunction, platform string, verbose bool) string { +func storeRenderItem(item *storeV2.StoreFunction, platform string) string { var b bytes.Buffer w := tabwriter.NewWriter(&b, 0, 0, 1, ' ', 0) - fmt.Fprintf(w, "Info for: %s\n\n", item.Title) - fmt.Fprintf(w, "%s\t%s\n", "Name", item.Name) + author := item.Author + if author == "" { + author = "unknown" + } + + fmt.Fprintf(w, "%s\t%s\n", "Title:", item.Title) + fmt.Fprintf(w, "%s\t%s\n", "Author:", item.Author) + fmt.Fprintf(w, "%s\t\n%s\n\n", "Description:", wordwrap.WrapString(item.Description, 80)) + + fmt.Fprintf(w, "%s\t%s\n", "Image:", item.GetImageName(platform)) + fmt.Fprintf(w, "%s\t%s\n", "Process:", item.Fprocess) + fmt.Fprintf(w, "%s\t%s\n", "Repo URL:", item.RepoURL) + if len(item.Environment) > 0 { + fmt.Fprintf(w, "Environment:\n") + for k, v := range item.Environment { + fmt.Fprintf(w, "- \t%s:\t%s\n", k, v) + } + fmt.Fprintln(w) + } - desc := item.Description - if !verbose { - desc = storeRenderDescription(desc) + if item.Labels != nil { + fmt.Fprintf(w, "Labels:\n") + for k, v := range item.Labels { + fmt.Fprintf(w, "- \t%s:\t%s\n", k, v) + } + fmt.Fprintln(w) } - fmt.Fprintf(w, "%s\t%s\n", "Description", desc) - fmt.Fprintf(w, "%s\t%s\n", "Image", item.GetImageName(platform)) - fmt.Fprintf(w, "%s\t%s\n", "Process", item.Fprocess) - fmt.Fprintf(w, "%s\t%s\n", "Repo URL", item.RepoURL) + if len(item.Annotations) > 0 { + fmt.Fprintf(w, "Annotations:\n") + for k, v := range item.Annotations { + fmt.Fprintf(w, "- \t%s:\t%s\n", k, v) + } + fmt.Fprintln(w) + } - fmt.Fprintln(w) w.Flush() return b.String() } diff --git a/commands/store_list.go b/commands/store_list.go index bfa1353b..a72eda11 100644 --- a/commands/store_list.go +++ b/commands/store_list.go @@ -55,10 +55,15 @@ func storeRenderItems(items []storeV2.StoreFunction) string { var b bytes.Buffer w := tabwriter.NewWriter(&b, 0, 0, 1, ' ', 0) fmt.Fprintln(w) - fmt.Fprintln(w, "FUNCTION\tDESCRIPTION") + fmt.Fprintln(w, "FUNCTION\tAUTHOR\tDESCRIPTION") for _, item := range items { - fmt.Fprintf(w, "%s\t%s\n", item.Title, storeRenderDescription(item.Description)) + author := item.Author + if author == "" { + author = "unknown" + } + + fmt.Fprintf(w, "%s\t%s\t%s\n", item.Name, author, storeRenderDescription(item.Title)) } fmt.Fprintln(w) diff --git a/go.mod b/go.mod index ad79ea5e..384ff48b 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,10 @@ require ( gopkg.in/yaml.v3 v3.0.1 ) -require github.com/google/go-containerregistry v0.13.0 +require ( + github.com/google/go-containerregistry v0.13.0 + github.com/mitchellh/go-wordwrap v1.0.1 +) require ( github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect diff --git a/go.sum b/go.sum index deb8fb87..a7b213cd 100644 --- a/go.sum +++ b/go.sum @@ -214,6 +214,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/schema/store/v2/store.go b/schema/store/v2/store.go index ea12abcd..393447b2 100644 --- a/schema/store/v2/store.go +++ b/schema/store/v2/store.go @@ -6,11 +6,11 @@ package v2 // StoreFunction represents a multi-arch function in the store type StoreFunction struct { Icon string `json:"icon"` + Author string `json:"author,omitempty"` Title string `json:"title"` Description string `json:"description"` Name string `json:"name"` Fprocess string `json:"fprocess"` - Network string `json:"network"` RepoURL string `json:"repo_url"` ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem"` Environment map[string]string `json:"environment"` diff --git a/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md new file mode 100644 index 00000000..22985159 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/mitchellh/go-wordwrap/README.md b/vendor/github.com/mitchellh/go-wordwrap/README.md new file mode 100644 index 00000000..60ae3117 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/README.md @@ -0,0 +1,39 @@ +# go-wordwrap + +`go-wordwrap` (Golang package: `wordwrap`) is a package for Go that +automatically wraps words into multiple lines. The primary use case for this +is in formatting CLI output, but of course word wrapping is a generally useful +thing to do. + +## Installation and Usage + +Install using `go get github.com/mitchellh/go-wordwrap`. + +Full documentation is available at +http://godoc.org/github.com/mitchellh/go-wordwrap + +Below is an example of its usage ignoring errors: + +```go +wrapped := wordwrap.WrapString("foo bar baz", 3) +fmt.Println(wrapped) +``` + +Would output: + +``` +foo +bar +baz +``` + +## Word Wrap Algorithm + +This library doesn't use any clever algorithm for word wrapping. The wrapping +is actually very naive: whenever there is whitespace or an explicit linebreak. +The goal of this library is for word wrapping CLI output, so the input is +typically pretty well controlled human language. Because of this, the naive +approach typically works just fine. + +In the future, we'd like to make the algorithm more advanced. We would do +so without breaking the API. diff --git a/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go new file mode 100644 index 00000000..f7bedda3 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go @@ -0,0 +1,83 @@ +package wordwrap + +import ( + "bytes" + "unicode" +) + +const nbsp = 0xA0 + +// WrapString wraps the given string within lim width in characters. +// +// Wrapping is currently naive and only happens at white-space. A future +// version of the library will implement smarter wrapping. This means that +// pathological cases can dramatically reach past the limit, such as a very +// long word. +func WrapString(s string, lim uint) string { + // Initialize a buffer with a slightly larger size to account for breaks + init := make([]byte, 0, len(s)) + buf := bytes.NewBuffer(init) + + var current uint + var wordBuf, spaceBuf bytes.Buffer + var wordBufLen, spaceBufLen uint + + for _, char := range s { + if char == '\n' { + if wordBuf.Len() == 0 { + if current+spaceBufLen > lim { + current = 0 + } else { + current += spaceBufLen + spaceBuf.WriteTo(buf) + } + spaceBuf.Reset() + spaceBufLen = 0 + } else { + current += spaceBufLen + wordBufLen + spaceBuf.WriteTo(buf) + spaceBuf.Reset() + spaceBufLen = 0 + wordBuf.WriteTo(buf) + wordBuf.Reset() + wordBufLen = 0 + } + buf.WriteRune(char) + current = 0 + } else if unicode.IsSpace(char) && char != nbsp { + if spaceBuf.Len() == 0 || wordBuf.Len() > 0 { + current += spaceBufLen + wordBufLen + spaceBuf.WriteTo(buf) + spaceBuf.Reset() + spaceBufLen = 0 + wordBuf.WriteTo(buf) + wordBuf.Reset() + wordBufLen = 0 + } + + spaceBuf.WriteRune(char) + spaceBufLen++ + } else { + wordBuf.WriteRune(char) + wordBufLen++ + + if current+wordBufLen+spaceBufLen > lim && wordBufLen < lim { + buf.WriteRune('\n') + current = 0 + spaceBuf.Reset() + spaceBufLen = 0 + } + } + } + + if wordBuf.Len() == 0 { + if current+spaceBufLen <= lim { + spaceBuf.WriteTo(buf) + } + } else { + spaceBuf.WriteTo(buf) + wordBuf.WriteTo(buf) + } + + return buf.String() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index bca9a1bc..795aaf6c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -131,6 +131,9 @@ github.com/mattn/go-runewidth # github.com/mitchellh/go-homedir v1.1.0 ## explicit github.com/mitchellh/go-homedir +# github.com/mitchellh/go-wordwrap v1.0.1 +## explicit; go 1.14 +github.com/mitchellh/go-wordwrap # github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae ## explicit; go 1.13 github.com/moby/term