Files
steampipe/pkg/cmdconfig/cmd_flags.go
kaidaguerre 07782a2b13 Adds support for verbose timing information. Closes #4237. Closes #4244
- JSON output format has changed to move the rows to under a `rows` property, with timing information under the `metadata` property
- Update timing display to show rows returned and rows fetched, as well as adding verbose mode which lists all scans
- Use enums for output mode and timing mode - timing is now either `on`, `off` or `verbose`
- Bugfix: ensure error is returned from ExecuteSystemClientCall. Closes #4246
2024-04-17 10:12:17 +01:00

66 lines
1.7 KiB
Go

package cmdconfig
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/turbot/steampipe/pkg/error_helpers"
)
var requiredColor = color.New(color.Bold).SprintfFunc()
type FlagOption func(c *cobra.Command, name string, key string)
// FlagOptions - shortcut for common flag options
var FlagOptions = struct {
Required func() FlagOption
Hidden func() FlagOption
Deprecated func(string) FlagOption
NoOptDefVal func(string) FlagOption
WithShortHand func(string) FlagOption
}{
Required: requiredOpt,
Hidden: hiddenOpt,
Deprecated: deprecatedOpt,
NoOptDefVal: noOptDefValOpt,
WithShortHand: withShortHand,
}
// Helper function to mark a flag as required
func requiredOpt() FlagOption {
return func(c *cobra.Command, name, key string) {
err := c.MarkFlagRequired(key)
error_helpers.FailOnErrorWithMessage(err, "could not mark flag as required")
key = fmt.Sprintf("required.%s", key)
viper.GetViper().Set(key, true)
u := c.Flag(name).Usage
c.Flag(name).Usage = fmt.Sprintf("%s %s", u, requiredColor("(required)"))
}
}
func hiddenOpt() FlagOption {
return func(c *cobra.Command, name, _ string) {
c.Flag(name).Hidden = true
}
}
func deprecatedOpt(replacement string) FlagOption {
return func(c *cobra.Command, name, _ string) {
c.Flag(name).Deprecated = fmt.Sprintf("please use %s", replacement)
}
}
func noOptDefValOpt(noOptDefVal string) FlagOption {
return func(c *cobra.Command, name, _ string) {
c.Flag(name).NoOptDefVal = noOptDefVal
}
}
func withShortHand(shorthand string) FlagOption {
return func(c *cobra.Command, name, _ string) {
c.Flag(name).Shorthand = shorthand
}
}