...

Package cmdopts

import "github.com/cybertec-postgresql/pgwatch/v3/internal/cmdopts"
Overview
Index

Overview ▾

Package cmdopts provides functionality to parse command line options and ENV variables.

Index ▾

Constants
func addCommands(parser *flags.Parser, opts *Options)
type ConfigCommand
    func NewConfigCommand(owner *Options) *ConfigCommand
type ConfigInitCommand
    func (cmd *ConfigInitCommand) Execute([]string) (err error)
    func (cmd *ConfigInitCommand) InitMetrics() (err error)
    func (cmd *ConfigInitCommand) InitSources() (err error)
type ConfigUpgradeCommand
    func (cmd *ConfigUpgradeCommand) Execute([]string) (err error)
type Kind
type MetricCommand
    func NewMetricCommand(owner *Options) *MetricCommand
type MetricPrintInitCommand
    func (cmd *MetricPrintInitCommand) Execute(args []string) error
type MetricPrintSQLCommand
    func (cmd *MetricPrintSQLCommand) Execute(args []string) error
type Options
    func New(writer io.Writer) (cmdOpts *Options, err error)
    func (c *Options) CompleteCommand(code int32)
    func (c *Options) GetConfigKind(arg string) (_ Kind, err error)
    func (c *Options) InitConfigReaders(ctx context.Context) error
    func (c *Options) InitMetricReader(ctx context.Context) (err error)
    func (c *Options) InitSinkWriter(ctx context.Context) (err error)
    func (c *Options) InitSourceReader(ctx context.Context) (err error)
    func (c *Options) IsPgConnStr(arg string) bool
    func (c *Options) NeedsSchemaUpgrade() (upgrade bool, err error)
    func (c *Options) ValidateConfig() error
    func (c *Options) Verbose() bool
type SourceCommand
    func NewSourceCommand(owner *Options) *SourceCommand
type SourcePingCommand
    func (cmd *SourcePingCommand) Execute(args []string) error
type SourceResolveCommand
    func (cmd *SourceResolveCommand) Execute(args []string) error

Package files

cmdconfig.go cmdmetric.go cmdoptions.go cmdsource.go doc.go

Constants

const (
    ExitCodeOK int32 = iota
    ExitCodeConfigError
    ExitCodeCmdError
    ExitCodeWebUIError
    ExitCodeUpgradeError
    ExitCodeUserCancel
    ExitCodeShutdownCommand
    ExitCodeFatalError
)

func addCommands

func addCommands(parser *flags.Parser, opts *Options)

type ConfigCommand

type ConfigCommand struct {
    owner   *Options
    Init    ConfigInitCommand    `command:"init" description:"Initialize configuration"`
    Upgrade ConfigUpgradeCommand `command:"upgrade" description:"Upgrade configuration schema"`
}

func NewConfigCommand

func NewConfigCommand(owner *Options) *ConfigCommand

type ConfigInitCommand

type ConfigInitCommand struct {
    owner *Options
}

func (*ConfigInitCommand) Execute

func (cmd *ConfigInitCommand) Execute([]string) (err error)

Execute initializes the configuration.

func (*ConfigInitCommand) InitMetrics

func (cmd *ConfigInitCommand) InitMetrics() (err error)

InitMetrics initializes the metrics configuration.

func (*ConfigInitCommand) InitSources

func (cmd *ConfigInitCommand) InitSources() (err error)

InitSources initializes the sources configuration.

type ConfigUpgradeCommand

type ConfigUpgradeCommand struct {
    owner *Options
}

func (*ConfigUpgradeCommand) Execute

func (cmd *ConfigUpgradeCommand) Execute([]string) (err error)

Execute upgrades the configuration schema.

type Kind

type Kind int
const (
    ConfigPgURL Kind = iota
    ConfigFile
    ConfigFolder
    ConfigError
)

type MetricCommand

type MetricCommand struct {
    owner     *Options
    PrintInit MetricPrintInitCommand `command:"print-init" description:"Get and print init SQL for a given metric or preset"`
    PrintSQL  MetricPrintSQLCommand  `command:"print-sql" description:"Get and print SQL for a given metric"`
}

func NewMetricCommand

func NewMetricCommand(owner *Options) *MetricCommand

type MetricPrintInitCommand

type MetricPrintInitCommand struct {
    owner *Options
}

func (*MetricPrintInitCommand) Execute

func (cmd *MetricPrintInitCommand) Execute(args []string) error

type MetricPrintSQLCommand

type MetricPrintSQLCommand struct {
    owner   *Options
    Version int `short:"v" long:"version" description:"PostgreSQL version to get SQL for"`
}

func (*MetricPrintSQLCommand) Execute

func (cmd *MetricPrintSQLCommand) Execute(args []string) error

type Options

Options contains the command line options.

type Options struct {
    Sources sources.CmdOpts   `group:"Sources"`
    Metrics metrics.CmdOpts   `group:"Metrics"`
    Sinks   sinks.CmdOpts     `group:"Sinks"`
    Logging log.CmdOpts       `group:"Logging"`
    WebUI   webserver.CmdOpts `group:"WebUI"`
    Help    bool

    SourcesReaderWriter sources.ReaderWriter
    MetricsReaderWriter metrics.ReaderWriter
    SinksWriter         sinks.Writer

    ExitCode         int32
    CommandCompleted bool

    OutputWriter io.Writer
}

func New

func New(writer io.Writer) (cmdOpts *Options, err error)

New returns a new instance of Options and immediately executes the subcommand if specified. Subcommands are responsible for setting exit code. Function prints help message only if options are incorrect. If subcommand is executed but fails, function outputs the error message only, indicating that some argument values might be incorrect, e.g. wrong file name, lack of privileges, etc.

func (*Options) CompleteCommand

func (c *Options) CompleteCommand(code int32)

func (*Options) GetConfigKind

func (c *Options) GetConfigKind(arg string) (_ Kind, err error)

func (*Options) InitConfigReaders

func (c *Options) InitConfigReaders(ctx context.Context) error

InitConfigReaders creates the configuration readers based on the configuration kind from the options.

func (*Options) InitMetricReader

func (c *Options) InitMetricReader(ctx context.Context) (err error)

InitMetricReader creates a new source reader based on the configuration kind from the options.

func (*Options) InitSinkWriter

func (c *Options) InitSinkWriter(ctx context.Context) (err error)

InitSinkWriter creates a new MultiWriter instance if needed.

func (*Options) InitSourceReader

func (c *Options) InitSourceReader(ctx context.Context) (err error)

InitSourceReader creates a new source reader based on the configuration kind from the options.

func (*Options) IsPgConnStr

func (c *Options) IsPgConnStr(arg string) bool

func (*Options) NeedsSchemaUpgrade

func (c *Options) NeedsSchemaUpgrade() (upgrade bool, err error)

NeedsSchemaUpgrade checks if the configuration database schema needs an upgrade.

func (*Options) ValidateConfig

func (c *Options) ValidateConfig() error

ValidateConfig checks if the configuration is valid. Configuration database can be specified for one of the --sources or --metrics. If one is specified, the other one is set to the same value.

func (*Options) Verbose

func (c *Options) Verbose() bool

Verbose returns true if the debug log is enabled

type SourceCommand

type SourceCommand struct {
    owner   *Options
    Ping    SourcePingCommand    `command:"ping" description:"Try to connect to configured sources, report errors if any and then exit"`
    Resolve SourceResolveCommand `command:"resolve" description:"Resolve monitored connections for a given sources (all by default)"`
}

func NewSourceCommand

func NewSourceCommand(owner *Options) *SourceCommand

type SourcePingCommand

type SourcePingCommand struct {
    owner *Options
}

func (*SourcePingCommand) Execute

func (cmd *SourcePingCommand) Execute(args []string) error

type SourceResolveCommand

type SourceResolveCommand struct {
    owner *Options
}

func (*SourceResolveCommand) Execute

func (cmd *SourceResolveCommand) Execute(args []string) error