From 251651cc9759587c59e2736113bdeecb02d1a714 Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Thu, 21 Nov 2019 15:43:10 -0800 Subject: [PATCH] feat(influx): add pkg summary cmd to influx cli --- cmd/influx/pkg.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/influx/pkg.go b/cmd/influx/pkg.go index fbb6dc32ef..11684ca2c5 100644 --- a/cmd/influx/pkg.go +++ b/cmd/influx/pkg.go @@ -76,6 +76,7 @@ func (b *cmdPkgBuilder) cmdPkg() *cobra.Command { cmd.AddCommand( b.cmdPkgNew(), b.cmdPkgExport(), + b.cmdPkgSummary(), b.cmdPkgValidate(), ) return cmd @@ -307,14 +308,35 @@ func (b *cmdPkgBuilder) pkgExportAllRunEFn() func(*cobra.Command, []string) erro } } +func (b *cmdPkgBuilder) cmdPkgSummary() *cobra.Command { + cmd := b.newCmd("summary") + cmd.Short = "Summarize the provided package" + + cmd.Flags().StringVarP(&b.file, "file", "f", "", "input file for pkg; if none provided will use TTY input") + cmd.Flags().BoolVarP(&b.hasColor, "color", "c", true, "Enable color in output, defaults true") + cmd.Flags().BoolVar(&b.hasTableBorders, "table-borders", true, "Enable table borders, defaults true") + + cmd.RunE = func(cmd *cobra.Command, args []string) error { + pkg, _, err := b.readPkgStdInOrFile(b.file) + if err != nil { + return err + } + + b.printPkgSummary(pkg.Summary()) + return nil + } + + return cmd +} + func (b *cmdPkgBuilder) cmdPkgValidate() *cobra.Command { cmd := b.newCmd("validate") cmd.Short = "Validate the provided package" - inPath := cmd.Flags().StringP("file", "f", "", "input file for pkg; if none provided will use TTY input") + cmd.Flags().StringVarP(&b.file, "file", "f", "", "input file for pkg; if none provided will use TTY input") cmd.RunE = func(cmd *cobra.Command, args []string) error { - pkg, _, err := b.readPkgStdInOrFile(*inPath) + pkg, _, err := b.readPkgStdInOrFile(b.file) if err != nil { return err }