config

package
v0.0.0-...-4f39b84 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config manages configuration files for the twig tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseParams

func ParseParams(args []string, kind string, opt OptionSetter) ([]string, error)

ParseParams parses optional parameters by name into an options struct. Parameter names are prefixed with a colon, for example ":entities". It returns the unconsumed arguments or reports a descriptive error for an unknown parameter name.

func PrintJSON

func PrintJSON(v interface{}) error

PrintJSON prints v as JSON to stdout. If v is a slice, the members of the slice are printed one by one; otherwise v is printed alone.

func ResolveID

func ResolveID(ctx context.Context, cli *twitter.Client, specs []string) ([]string, error)

ResolveID checks a slice of user specifications and attempts to resolve any that begin with "@" with their user ID.

func Save

func Save(cfg *Config, path string) error

Save writes cfg to path.

Types

type Config

type Config struct {
	// Required fields. See: https://developer.twitter.com/en/portal/dashboard
	APIKey      string `yaml:"api_key"`
	APISecret   string `yaml:"api_secret"`
	Token       string `yaml:"access_token"`
	Secret      string `yaml:"access_secret"`
	BearerToken string `yaml:"bearer_token,omitempty"`

	Users []*User `yaml:"users,omitempty"`

	AuthUser string                            `yaml:"-"`
	Log      func(tag jape.LogTag, msg string) `yaml:"-"`
	LogMask  jape.LogTag                       `yaml:"-"`
	// contains filtered or unexported fields
}

Config represents the stored configuration data for the twig tools.

func Load

func Load(path string) (*Config, error)

Load reads in the contents of a config file from path.

func (*Config) FindUsername

func (c *Config) FindUsername(name string) *User

FindUsername returns the access token for the given username, or nil.

func (*Config) NewBearerClient

func (c *Config) NewBearerClient() (*twitter.Client, error)

NewBearerClient returns a new Twitter client with a bearer token.

func (*Config) NewClient

func (c *Config) NewClient() (*twitter.Client, error)

NewClient returns a new Twitter client from selected settings.

func (*Config) NewUserClient

func (c *Config) NewUserClient(user string) (*twitter.Client, error)

NewUserClient returns a new Twitter client with an access token for the specified username.

func (*Config) Save

func (c *Config) Save() error

Save writes the current state of c back to its original file.

type OptionSetter

type OptionSetter interface {
	Set(string, bool) bool
}

OptionSetter represents the ability to set named optional Boolean options. This interface is satisfied by the option types from the twitter package.

type ParsedArgs

type ParsedArgs struct {
	Keys   []string // all arguments that are not field specs, in the order given
	Fields []types.Fields
}

ParsedArgs is the result from a call to ParseArgs.

func ParseArgs

func ParseArgs(args []string, dtype string) ParsedArgs

ParseArgs decodes an argument list consisting of IDs or names mixed with field specifiers and expansions. A field spec has the form "name:value", where name is the object type (for example "tweet", "user"), and value is an arbitrary string. An expansion has the form "+name".

If dtype != "", a spec of the form ":value" is treated as "dtype:value".

type User

type User struct {
	Username string `yaml:"username"`
	Token    string `yaml:"token"`
	Secret   string `yaml:"secret"`
}

User carries an access token for an individual user.

Jump to

Keyboard shortcuts

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