Add render sub-command frame
Render command filters documents and prints them to user-defined output in a form of multi-document YAML. Sub-command receives following document filter flags: * label * annotation * apiVersion (a.k.a group-version) * kind * filter Related: #16 Change-Id: I7efb0a478e1070efd1791ab10d7c3946c8c28630
This commit is contained in:
parent
5aebf87fc2
commit
ff917e5a49
cmd/document
pkg/document/render
@ -16,6 +16,7 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
|
||||
|
||||
documentRootCmd.AddCommand(NewDocumentPullCommand(rootSettings))
|
||||
documentRootCmd.AddCommand(secret.NewSecretCommand(rootSettings))
|
||||
documentRootCmd.AddCommand(NewRenderCommand(rootSettings))
|
||||
|
||||
return documentRootCmd
|
||||
}
|
||||
|
26
cmd/document/document_test.go
Normal file
26
cmd/document/document_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"opendev.org/airship/airshipctl/cmd/document"
|
||||
"opendev.org/airship/airshipctl/testutil"
|
||||
)
|
||||
|
||||
func TestDocument(t *testing.T) {
|
||||
tests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "document-with-defaults",
|
||||
CmdLine: "",
|
||||
Cmd: document.NewDocumentCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "document-render-with-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: document.NewRenderCommand(nil),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
testutil.RunTest(t, tt)
|
||||
}
|
||||
}
|
34
cmd/document/render.go
Normal file
34
cmd/document/render.go
Normal file
@ -0,0 +1,34 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/document/render"
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
"opendev.org/airship/airshipctl/pkg/errors"
|
||||
)
|
||||
|
||||
// InitFlags add flags for document render sub-command
|
||||
func initRenderFlags(settings *render.Settings, cmd *cobra.Command) {
|
||||
flags := cmd.Flags()
|
||||
flags.StringArrayVarP(&settings.Label, "label", "l", nil, "Filter documents by Labels")
|
||||
flags.StringArrayVarP(&settings.Annotation, "annotation", "a", nil, "Filter documents by Annotations")
|
||||
flags.StringArrayVarP(&settings.GroupVersion, "apiversion", "g", nil, "Filter documents by API version")
|
||||
flags.StringArrayVarP(&settings.Kind, "kind", "k", nil, "Filter documents by Kinds")
|
||||
flags.StringVarP(&settings.RawFilter, "filter", "f", "", "Logical expression for document filtering")
|
||||
}
|
||||
|
||||
// NewRenderCommand create a new command for document rendering
|
||||
func NewRenderCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
renderSettings := &render.Settings{AirshipCTLSettings: rootSettings}
|
||||
renderCmd := &cobra.Command{
|
||||
Use: "render",
|
||||
Short: "Render documents from model",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return errors.ErrNotImplemented{}
|
||||
},
|
||||
}
|
||||
|
||||
initRenderFlags(renderSettings, renderCmd)
|
||||
return renderCmd
|
||||
}
|
12
cmd/document/testdata/TestDocumentGoldenOutput/document-render-with-help.golden
vendored
Normal file
12
cmd/document/testdata/TestDocumentGoldenOutput/document-render-with-help.golden
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
Render documents from model
|
||||
|
||||
Usage:
|
||||
render [flags]
|
||||
|
||||
Flags:
|
||||
-a, --annotation stringArray Filter documents by Annotations
|
||||
-g, --apiversion stringArray Filter documents by API version
|
||||
-f, --filter string Logical expression for document filtering
|
||||
-h, --help help for render
|
||||
-k, --kind stringArray Filter documents by Kinds
|
||||
-l, --label stringArray Filter documents by Labels
|
15
cmd/document/testdata/TestDocumentGoldenOutput/document-with-defaults.golden
vendored
Normal file
15
cmd/document/testdata/TestDocumentGoldenOutput/document-with-defaults.golden
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
manages deployment documents
|
||||
|
||||
Usage:
|
||||
document [command]
|
||||
|
||||
Available Commands:
|
||||
help Help about any command
|
||||
pull pulls documents from remote git repository
|
||||
render Render documents from model
|
||||
secret manages secrets
|
||||
|
||||
Flags:
|
||||
-h, --help help for document
|
||||
|
||||
Use "document [command] --help" for more information about a command.
|
20
pkg/document/render/type.go
Normal file
20
pkg/document/render/type.go
Normal file
@ -0,0 +1,20 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
// Settings for document rendering
|
||||
type Settings struct {
|
||||
*environment.AirshipCTLSettings
|
||||
// Label filter documents by label string
|
||||
Label []string
|
||||
// Annotation filter documents by annotation string
|
||||
Annotation []string
|
||||
// GroupVersion filter documents by API version
|
||||
GroupVersion []string
|
||||
// Kind filter documents by document kind
|
||||
Kind []string
|
||||
// RawFilter contains logical expression to filter documents
|
||||
RawFilter string
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user