qbcli

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionDumpDirectory  = "dump-dir"
	OptionFormat         = "format"
	OptionJMESPathFilter = "filter"
	OptionLogFile        = "log-file"
	OptionLogLevel       = "log-level"
	OptionQuiet          = "quiet"
)

Option* constants contain CLI options.

View Source
const (
	OptionAppIDDescription         = "unique identifier of an app (required)"
	OptionFieldIDDescription       = "unique identifier (fid) of the field (required)"
	OptionParentTableIDDescription = "unique identifier (dbid) of the parent table (required)"
	OptionTableIDDescription       = "unique identifier (dbid) of the table (required)"
	OptionQuietDescription         = "suppress output written to stdout"
)

Option*Description constants contain common option descriptions.

Variables

View Source
var (
	TestsFailed = qberrors.ErrSafe{Message: "tests failed", StatusCode: http.StatusBadRequest}
)

Functions

func CacheTableSchema added in v0.2.0

func CacheTableSchema(qb *qbclient.Client, tableID string) error

CacheTableSchema caches schema information for a table.

func Export added in v0.2.0

func Export(qb *qbclient.Client, opts *ExportOptions) error

Export exports data from a Quickbase table into an io.Writer.

func GetOptions

func GetOptions(ctx context.Context, logger *cliutil.LeveledLogger, input interface{}, cfg *viper.Viper)

GetOptions gets options based on the input and validates them.

func HandleError

func HandleError(ctx context.Context, logger *cliutil.LeveledLogger, message string, err error)

HandleError handles an error by logging it and returning a non-zero status. We reserve Fatal errors for internal problems.

func Import added in v0.2.0

Import imports data from an io.Reader into a Quickbase table.

func NewClient

func NewClient(cmd *cobra.Command, cfg GlobalConfig) (ctx context.Context, logger *cliutil.LeveledLogger, qb *qbclient.Client)

NewClient returns a new *qbclient.Client.

func NewDumpPlugin

func NewDumpPlugin(ctx context.Context, logger *cliutil.LeveledLogger, transid string, directory string) qbclient.Plugin

NewDumpPlugin returns a DumpPlugin, which implements qbclient.Plugin.

func NewGroupOption

func NewGroupOption(tag map[string]string) cliutil.OptionType

NewGroupOption is a cliutil.OptionTypeFunc that returns a *cliutil.GroupOption.

func NewLogger

func NewLogger(cmd *cobra.Command, cfg GlobalConfig) (ctx context.Context, logger *cliutil.LeveledLogger, transid xid.ID)

NewLogger returns a new *cliutil.LeveledLogger.

func NewLoggerPlugin

func NewLoggerPlugin(ctx context.Context, logger *cliutil.LeveledLogger) qbclient.Plugin

NewLoggerPlugin returns a LoggerPlugin, which implements qbclient.Plugin.

func NewQueryOption

func NewQueryOption(tag map[string]string) cliutil.OptionType

NewQueryOption is a cliutil.OptionTypeFunc that returns a *cliutil.QueryOption.

func NewRecordOption

func NewRecordOption(tag map[string]string) cliutil.OptionType

NewRecordOption is a cliutil.OptionTypeFunc that returns a *cliutil.RecordOption.

func NewSortOption

func NewSortOption(tag map[string]string) cliutil.OptionType

NewSortOption is a cliutil.OptionTypeFunc that returns a *cliutil.SortOption.

func ParseGroupBy

func ParseGroupBy(s string) (groupBy []*qbclient.QueryRecordsInputGroupBy, err error)

ParseGroupBy parses the groupBy clause.

func ParseQuery

func ParseQuery(q string) string

ParseQuery parses queries. It also detcts and transforms simple queries into Quick Base query syntax.

func ParseSortBy

func ParseSortBy(s string) (sortBy []*qbclient.QueryRecordsInputSortBy, err error)

ParseSortBy parses the sortBy clause.

func Prompt

func Prompt(label string, validate qbclient.ValidateStringFn) (s string, err error)

Prompt prompts a user for input and returns what they typed.

func Render

func Render(
	ctx context.Context,
	logger *cliutil.LeveledLogger,
	cmd *cobra.Command,
	cfg GlobalConfig,
	v interface{},
	err error,
)

Render renders the output in JSON, or writes an error log.

func SetOptionFromArg

func SetOptionFromArg(cfg *viper.Viper, args []string, idx int, option string)

SetOptionFromArg sets an option from an argument.

func TestsFailedError added in v0.2.7

func TestsFailedError(format string, a ...interface{}) error

Types

type DeployFormulaInput added in v0.2.4

type DeployFormulaInput struct {
	File string `cliutil:"option=file default=quickbase.yml"`
}

type DeployFormulaOutput added in v0.2.4

type DeployFormulaOutput struct {
	Deployed map[string][]int          `json:"deployed"`
	Errors   map[string]map[int]string `json:"errors"`
}

func DeployFormula added in v0.2.4

func DeployFormula(qb *qbclient.Client, in *DeployFormulaInput) (out *DeployFormulaOutput, err error)

type DumpPlugin

type DumpPlugin struct {
	// contains filtered or unexported fields
}

DumpPlugin implements qbclient.Plugin and dumps requests and responses to files in a directory.

func (DumpPlugin) PostResponse

func (p DumpPlugin) PostResponse(resp *http.Response)

PostResponse implements qbclient.Plugin.PostResponse.

func (DumpPlugin) PreRequest

func (p DumpPlugin) PreRequest(req *http.Request)

PreRequest implements qbclient.Plugin.PreRequest.

type ExportOptions added in v0.2.0

type ExportOptions struct {
	TableID   string `validate:"required" cliutil:"option=table-id"`
	Filepath  string `cliutil:"option=file usage='file the data is exported to'"`
	BatchSize int    `cliutil:"option=batch-size default=10000"`
	Delay     int    `cliutil:"option=delay"`
}

ExportOptions are the options read through the command line.

type FieldMap added in v0.2.0

type FieldMap map[int]*qbclient.ListFieldsOutputField

FieldMap is a map of field IDs to field definitions.

func GetCachedTableSchema added in v0.2.0

func GetCachedTableSchema(tableID string) (FieldMap, error)

GetCachedTableSchema returns schema information for a table.

TODO Caching beyond in-memory caching?

func GetTableSchema added in v0.2.0

func GetTableSchema(qb *qbclient.Client, tableID string) (FieldMap, error)

GetTableSchema returns schema information for a table. If the schema is not in the in-memory cache, it retrieves the data and caches it.

type GlobalConfig

type GlobalConfig struct {
	// contains filtered or unexported fields
}

GlobalConfig contains configuration common to all commands.

func NewGlobalConfig

func NewGlobalConfig(cmd *cobra.Command, cfg *viper.Viper) GlobalConfig

NewGlobalConfig returns a GlobalConfig.

func (GlobalConfig) ConfigDir

func (c GlobalConfig) ConfigDir() string

ConfigDir returns the configuration directory.

func (GlobalConfig) DefaultAppID

func (c GlobalConfig) DefaultAppID() string

DefaultAppID returns the default app ID.

func (GlobalConfig) DefaultFieldID

func (c GlobalConfig) DefaultFieldID() int

DefaultFieldID returns the default field ID.

func (GlobalConfig) DefaultTableID

func (c GlobalConfig) DefaultTableID() string

DefaultTableID returns the default table ID.

func (GlobalConfig) DumpDirectory

func (c GlobalConfig) DumpDirectory() string

DumpDirectory returns the configured dump file directory.

func (GlobalConfig) Format added in v0.1.4

func (c GlobalConfig) Format() string

Format returns the configured output format, e.g., table. No config == JSON.

func (GlobalConfig) JMESPathFilter

func (c GlobalConfig) JMESPathFilter() string

JMESPathFilter returns the JMESPath filter.

func (GlobalConfig) LogFile

func (c GlobalConfig) LogFile() string

LogFile returns the configured log file.

func (GlobalConfig) LogLevel

func (c GlobalConfig) LogLevel() string

LogLevel returns the configured log level.

func (GlobalConfig) Profile

func (c GlobalConfig) Profile() string

Profile returns the configured profile.

func (GlobalConfig) Quiet

func (c GlobalConfig) Quiet() bool

Quiet returns whehter to suppress output written to stdout.

func (*GlobalConfig) ReadInConfig

func (c *GlobalConfig) ReadInConfig() error

ReadInConfig reads in the config file.

func (GlobalConfig) RealmHostname

func (c GlobalConfig) RealmHostname() string

RealmHostname returns the configured realm hostname.

func (GlobalConfig) SetDefaultAppID

func (c GlobalConfig) SetDefaultAppID(cfg *viper.Viper)

SetDefaultAppID sets the default app in the command's configuration.

func (GlobalConfig) SetDefaultTableID

func (c GlobalConfig) SetDefaultTableID(cfg *viper.Viper)

SetDefaultTableID sets the default table in the command's configuration.

func (GlobalConfig) SetDefaultTableIDs added in v0.2.0

func (c GlobalConfig) SetDefaultTableIDs(cfg *viper.Viper, key string)

SetDefaultTableIDs sets the default table in the command's configuration as the key option.

func (GlobalConfig) UserToken

func (c GlobalConfig) UserToken() string

UserToken returns the configured log level.

func (*GlobalConfig) Validate

func (c *GlobalConfig) Validate() error

Validate reads the configuration file and validates the global configuration options.

type GroupOption

type GroupOption struct {
	// contains filtered or unexported fields
}

GroupOption implements Option for string options that contain queries.

func (*GroupOption) Read

func (opt *GroupOption) Read(cfg *viper.Viper, field reflect.Value) error

Read implements cliutil.OptionType.Read.

func (*GroupOption) Set

func (opt *GroupOption) Set(f *cliutil.Flagger) error

Set implements cliutil.OptionType.Set.

type ImportOptions added in v0.2.0

type ImportOptions struct {
	TableID      string            `validate:"required" cliutil:"option=table-id"`
	Filepath     string            `cliutil:"option=file usage='file the data is imported from'"`
	BatchSize    int               `cliutil:"option=batch-size default=10000"`
	Map          map[string]string `cliutil:"option=map"`
	Delay        int               `cliutil:"option=delay"`
	Timeout      int               `cliutil:"option=timeout default=5 usage='timeout in seconds waiting for data to be read from stdin'"`
	MergeFieldID int               `cliutil:"option=merge-field-id"`
}

ImportOptions are the options read through the command line.

type LoggerPlugin

type LoggerPlugin struct {
	// contains filtered or unexported fields
}

LoggerPlugin implements qbclient.Plugin and logs requests.

func (LoggerPlugin) PostResponse

func (p LoggerPlugin) PostResponse(resp *http.Response)

PostResponse implements qbclient.Plugin.PostResponse.

func (LoggerPlugin) PreRequest

func (p LoggerPlugin) PreRequest(req *http.Request)

PreRequest implements qbclient.Plugin.PreRequest.

type QueryOption

type QueryOption struct {
	// contains filtered or unexported fields
}

QueryOption implements Option for string options that contain queries.

func (*QueryOption) Read

func (opt *QueryOption) Read(cfg *viper.Viper, field reflect.Value) error

Read implements cliutil.OptionType.Read.

func (*QueryOption) Set

func (opt *QueryOption) Set(f *cliutil.Flagger) error

Set implements cliutil.OptionType.Set.

type QuickbaseFile added in v0.2.4

type QuickbaseFile struct {
	Test   *QuickbaseFileTest   `yaml:"test"`
	Deploy *QuickbaseFileDeploy `yaml:"deploy"`
}

QuickbaseFile models a quickbase.yml file.

func ParseQuickbaseFile added in v0.2.4

func ParseQuickbaseFile(file string) (f *QuickbaseFile, err error)

type QuickbaseFileDeploy added in v0.2.4

type QuickbaseFileDeploy struct {
	Formulas []*QuickbaseFileDeployFormula `yaml:"formulas"`
}

type QuickbaseFileDeployFormula added in v0.2.4

type QuickbaseFileDeployFormula struct {
	File    string `validate:"required" yaml:"file"`
	TableID string `validate:"required" yaml:"table_id"`
	FieldID int    `validate:"required" yaml:"field_id"`
}

type QuickbaseFileTest added in v0.2.7

type QuickbaseFileTest struct {
	Formulas []*QuickbaseFileTestFormula `yaml:"formulas"`
}

type QuickbaseFileTestFormula added in v0.2.7

type QuickbaseFileTestFormula struct {
	File     string `validate:"required" yaml:"file"`
	TableID  string `validate:"required" yaml:"table_id"`
	RecordID int    `validate:"required" yaml:"record_id"`
	Expected string `validate:"required" yaml:"expected"`
}

type RecordOption

type RecordOption struct {
	// contains filtered or unexported fields
}

RecordOption implements Option for string options that contain record datas.

func (*RecordOption) Read

func (opt *RecordOption) Read(cfg *viper.Viper, field reflect.Value) error

Read implements cliutil.OptionType.Read.

func (*RecordOption) Set

func (opt *RecordOption) Set(f *cliutil.Flagger) error

Set implements cliutil.OptionType.Set.

type SortOption

type SortOption struct {
	// contains filtered or unexported fields
}

SortOption implements Option for string options that contain queries.

func (*SortOption) Read

func (opt *SortOption) Read(cfg *viper.Viper, field reflect.Value) error

Read implements cliutil.OptionType.Read.

func (*SortOption) Set

func (opt *SortOption) Set(f *cliutil.Flagger) error

Set implements cliutil.OptionType.Set.

type TestFormulaInput added in v0.2.7

type TestFormulaInput struct {
	File string `cliutil:"option=file default=quickbase.yml"`
}

type TestFormulaOutput added in v0.2.7

type TestFormulaOutput struct {
	Passed []int          `json:"passed"`
	Failed map[int]string `json:"failed"`
}

func TestFormula added in v0.2.7

func TestFormula(qb *qbclient.Client, in *TestFormulaInput) (out *TestFormulaOutput, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL