providers

package
v0.0.0-...-8f4bd53 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoAdd

func DoAdd(args *Args, cmd string) error

DoAdd is the high-level entry point for 'add'.

func DoBlocklistUpdate

func DoBlocklistUpdate(args *Args) error

DoBlocklistUpdate is the high-level entry point for 'blocklist-update'.

func DoConfig

func DoConfig(args *Args, cmd string) error

DoConfig is the high-level entry point for 'config'.

func DoFilesGet

func DoFilesGet(args *Args) error

DoFilesGet is the high-level entry point for 'files get'.

func DoFilesRename

func DoFilesRename(args *Args) error

DoFilesRename is the high-level entry point for 'files rename'.

func DoFilesSet

func DoFilesSet(field string) func(args *Args) error

DoFilesSet generates a torrent set request to change the specified field.

func DoFilesSetPriority

func DoFilesSetPriority(args *Args) error

DoFilesSetPriority is the high-level entry point for 'files set-priority'.

func DoFreeSpace

func DoFreeSpace(args *Args) error

DoFreeSpace is the high-level entry point for 'free-space'.

func DoGet

func DoGet(args *Args, cmd string) error

DoGet is the high-level entry point for 'get'.

func DoMove

func DoMove(args *Args) error

DoMove is the high-level entry point for 'move'.

func DoPeersGet

func DoPeersGet(args *Args) error

DoPeersGet is the high-level entry point for 'peers get'.

func DoPortTest

func DoPortTest(args *Args) error

DoPortTest is the high-level entry point for 'port-test'.

func DoRemove

func DoRemove(args *Args) error

DoRemove is the high-level entry point for 'remove'.

func DoReq

func DoReq(f func(...interface{}) *transrpc.Request) func(*Args) error

DoReq creates the high-level entry points for general torrent manipulation requests.

func DoSet

func DoSet(args *Args, cmd string) error

DoSet is the high-level entry point for 'set'.

func DoShutdown

func DoShutdown(args *Args) error

DoShutdown is the high-level entry point for 'shutdown'.

func DoStats

func DoStats(args *Args) error

DoStats is the high-level entry point for 'stats'.

func DoTrackersAdd

func DoTrackersAdd(args *Args) error

DoTrackersAdd is the high-level entry point for 'trackers add'.

func DoTrackersGet

func DoTrackersGet(args *Args) error

DoTrackersGet is the high-level entry point for 'trackers get'.

func DoTrackersRemove

func DoTrackersRemove(args *Args) error

DoTrackersRemove is the high-level entry point for 'trackers remove'.

func DoTrackersReplace

func DoTrackersReplace(args *Args) error

DoTrackersReplace is the high-level entry point for 'trackers replace'.

func Register

func Register(name string, f func(*Args) (Provider, error))

Register registers a provider.

Types

type Args

type Args struct {

	// ConfigFile is the global config file.
	ConfigFile string

	// Context is the global context name.
	Context string

	// Verbose is the global verbose toggle.
	Verbose bool

	// Host contains the global host configuration.
	Host struct {
		// URL is the URL to work with.
		URL *url.URL

		// Proto is the proto to use for building URLs.
		Proto string

		// Host is the host and port to use for building URLs.
		Host string

		// RpcPath is the rpc path to use for building URLs.
		RpcPath string

		// Credentials is the user:pass credentials to work with.
		Credentials string

		// CredentialsWasSet is the credentials was set toggle.
		CredentialsWasSet bool

		// Timeout is the rpc host request timeout.
		Timeout time.Duration

		// NoNetrc toggles disabling .netrc loading.
		NoNetrc bool

		// NetRCFile is the NetRCFile to use.
		NetrcFile string
	}

	// Filter contains the global filter configuration.
	Filter struct {
		// ListAll is the all toggle.
		ListAll bool

		// Recent is the recent toggle.
		Recent bool

		// Filter is the torrent filter.
		Filter string

		// FilterWasSet is the filter set toggle.
		FilterWasSet bool
	}

	// Output contains the global output configuration.
	Output struct {
		// Output is the output format type.
		Output string

		// OutputWasSet is the output was set toggle.
		OutputWasSet bool

		// Human is the toggle to display sizes in powers of 1024 (ie, 1023MiB).
		Human string

		// SI is the toggle to display sizes in powers of 1000 (ie, 1.1GB).
		SI bool

		// SIWasSet is the si was set toggle.
		SIWasSet bool

		// NoHeaders is the toggle to disable headers on table output.
		NoHeaders bool

		// NoTotals is the toggle to disable the total line on table output.
		NoTotals bool

		// ColumnNames is the column name map.
		ColumnNames map[string]string

		// SortBy is the to sort by field.
		SortBy string

		// SortByWasSet is the sort by was set toggle.
		SortByWasSet bool

		// SortOrder is the sort order direction.
		SortOrder string

		// SortOrderWasSet is the sort order was set toggle
		SortOrderWasSet bool
	}

	// ConfigParams are the config params.
	ConfigParams struct {
		Remote bool
		Name   string
		Value  string
		Unset  bool
	}

	// AddParams are the add params.
	AddParams struct {
		Cookies           map[string]string
		DownloadDir       string
		Paused            bool
		PeerLimit         int64
		BandwidthPriority int64
		Remove            bool
		RemoveWasSet      bool
	}

	// StartParams are the start params.
	StartParams struct {
		Now bool
	}

	// MoveParams are the move params.
	MoveParams struct {
		Dest string
	}

	// RemoveParams are the remove params.
	RemoveParams struct {
		Remove bool
	}

	// FilesSetPriorityParams are the files set-priority params.
	FilesSetPriorityParams struct {
		Priority string
	}

	// FilesRenameParams are the files rename params.
	FilesRenameParams struct {
		OldPath string
		NewPath string
	}

	// TrackersReplacePramas are the trackers replace params.
	TrackersReplaceParams struct {
		Replace string
	}

	// FileMask is the file mask for files operations.
	FileMask string

	// Tracker is the tracker for trackers operations.
	Tracker string

	// Args are remaining global arguments.
	Args []string

	// Config is the loaded settings from the config file.
	Config *ini.File
	// contains filtered or unexported fields
}

Args holds command args.

func NewArgs

func NewArgs(name, version string) (*Args, string, error)

NewArgs creates the command args.

func (*Args) NewProvider

func (args *Args) NewProvider() (Provider, error)

NewProvider creates a new provider based on the configured type of the remote host.

func (*Args) ResultOptions

func (args *Args) ResultOptions(opts ...ResultOption) []ResultOption

ResultOptions builds result options for arguments.

type ConfigStore

type ConfigStore interface {
	GetKey(string) string
	SetKey(string, string)
	RemoveKey(string)
	GetMapFlat() map[string]string
	GetAllFlat() []string
	Write(string) error
}

ConfigStore is the interface for config stores.

type Error

type Error string

Error is the error type.

const (
	// ErrMustSpecifyListRecentFilterOrAtLeastOneTorrent is the must specify
	// list, recent, filter or at least one torrent error.
	ErrMustSpecifyListRecentFilterOrAtLeastOneTorrent Error = "must specify --list, --recent, --filter or at least one torrent"

	// ErrMustSpecifyListOrOptionName is the must specify list or option name
	// error.
	ErrMustSpecifyListOrOptionName Error = "must specify --list or option name"

	// ErrConfigFileCannotBeADirectory is the config file cannot be a directory
	// error.
	ErrConfigFileCannotBeADirectory Error = "config file cannot be a directory"

	// ErrMustSpecifyAtLeastOneLocation is the must specify at least one
	// location error.
	ErrMustSpecifyAtLeastOneLocation Error = "must specify at least one location"

	// ErrCannotSpecifyUnsetAndAlsoSetAnOptionValue is the cannot specify unset
	// and also set an option value error.
	ErrCannotSpecifyUnsetAndAlsoSetAnOptionValue Error = "cannot specify --unset and also set an option value"

	// ErrInvalidProtoHostOrRpcPath is the invalid proto, host, or rpc-path
	// error.
	ErrInvalidProtoHostOrRpcPath Error = "invalid --proto, --host, or --rpc-path"

	// ErrCannotListAllOptionsAndUnset is the cannot list all options and unset
	// error.
	ErrCannotListAllOptionsAndUnset Error = "cannot --list all options and --unset"

	// ErrCannotUnsetARemoteConfigOption is the cannot unset a remote config
	// option error.
	ErrCannotUnsetARemoteConfigOption Error = "cannot --unset a --remote config option"

	// ErrMustSpecifyConfigOptionNameToUnset is the must specify config option
	// name to unset error.
	ErrMustSpecifyConfigOptionNameToUnset Error = "must specify config option name to --unset"

	// ErrInvalidOutputOptionSpecified is the invalid output option specified
	// error.
	ErrInvalidOutputOptionSpecified Error = "invalid --output option specified"

	// ErrSortByNotInColumnList is the sort by not in column list error.
	ErrSortByNotInColumnList Error = "--sort-by not in column list"

	// ErrMustSpecifyAtLeastOneOutputColumn is the must specify at least one output column error.
	ErrMustSpecifyAtLeastOneOutputColumn Error = "must specify at least one output column"

	// ErrFilterMustReturnBool is the filter must return bool error.
	ErrFilterMustReturnBool Error = "filter must return bool"

	// ErrInvalidStrlenArguments is the invalid strlen arguments error.
	ErrInvalidStrlenArguments Error = "invalid strlen() arguments"
)

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type Provider

type Provider interface {
	// NewRemoteConfigStore creates a config store for the remote host.
	NewRemoteConfigStore(context.Context) (ConfigStore, error)

	// Add adds a torrent ([]byte) or magnet link (string).
	Add(context.Context, ...interface{}) ([]tctypes.Torrent, error)

	// Get returns a semi-populated torrent list, with the provided fields.
	Get(context.Context, []string, ...interface{}) ([]tctypes.Torrent, error)

	// Set sets a configuration option on a torrent.
	Set(context.Context, map[string]interface{}) error

	// Start starts the provided identifiers.
	Start(context.Context, ...interface{}) error

	// Stop stops the provided identifiers.
	Stop(context.Context, ...interface{}) error

	// Move moves the provided identifiers
	Move(context.Context, string, ...interface{}) error

	// Remove removes the provided identifiers.
	Remove(context.Context, bool, ...interface{}) error

	// Verify verifies the provided identifiers.
	Verify(context.Context, ...interface{}) error

	// Reannounce reannounces the provided identifiers.
	Reannounce(context.Context, ...interface{}) error

	// Queue sets the queue position (top, bottom, up, down) for the provided identifiers.
	Queue(context.Context, string, ...interface{}) error

	// PeersGet returns the peers for the provided identifiers.
	PeersGet(context.Context, ...interface{}) ([]tctypes.Peer, error)

	// FilesGet returns the files for the provided identifiers.
	FilesGet(context.Context, ...interface{}) ([]tctypes.File, error)

	// FilesSet sets a file config option on the provided identifiers.
	FilesSet(context.Context, map[string]interface{}, ...interface{}) error

	// FilesRename renames a file on the provided identifiers.
	FilesRename(context.Context, string, string, ...interface{}) error

	// TrackersGet returns the trackers for the provided identifiers.
	TrackersGet(context.Context, ...interface{}) ([]tctypes.Tracker, error)

	// TrackersAdd adds a tracker to the provided identifiers.
	TrackersAdd(context.Context, string, ...interface{}) error

	// TrackersReplace replaces a tracker on the provided identifiers.
	TrackersReplace(context.Context, string, string, ...interface{}) error

	// TrackersRemove removes a tracker from the provided identifiers.
	TrackersRemove(context.Context, string, ...interface{}) error

	// Stats returns the stats for the remote host.
	Stats(context.Context) (map[string]interface{}, error)

	// Shutdown shuts down the remote host.
	Shutdown(context.Context) error

	// FreeSpace returns the free space for the provided location.
	FreeSpace(context.Context, string) (tctypes.ByteCount, error)

	// BlocklistUpdate tells the remote host to update its blocklist.
	BlocklistUpdate(context.Context) (int64, error)

	// PortTest tells the remote to do a port test.
	PortTest(context.Context) (bool, error)
}

Provider is a torrent provider.

type Result

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

Result is a wraper for a slice of structs. Uses reflection to iterate the items and output based on

func NewResult

func NewResult(v interface{}, options ...ResultOption) *Result

NewResult creates a new reflection result for v.

func (*Result) Encode

func (res *Result) Encode(w io.Writer) error

Encode encodes the result using the settings in args to the io.Writer.

type ResultOption

type ResultOption = func(*Result)

ResultOption is a result option.

func ColumnNames

func ColumnNames(columnNames map[string]string) ResultOption

ColumnNames is a result option to set the column names map.

func FlatIndex

func FlatIndex(flatIndex string) ResultOption

FlatIndex is a result option to set the flat index key.

func FlatKey

func FlatKey(flatKey string) ResultOption

FlatKey is a result option to set the flat key field.

func FlatName

func FlatName(flatName string) ResultOption

FlatName is a result option to set the flat key used for output.

func FormatBytes

func FormatBytes(formatBytes func(tctypes.ByteFormatter) string) ResultOption

FormatBytes is a result option to set the func used to format bytes.

func Index

func Index(index string) ResultOption

Index sets the index field to use.

func NoHeaders

func NoHeaders(noHeaders bool) ResultOption

NoHeaders is a result option to set the no headers toggle.

func NoTotals

func NoTotals(noTotals bool) ResultOption

NoTotals is a result option to set the no totals toggle.

func Output

func Output(output string) ResultOption

Output is a result option to set the output format.

func SortBy

func SortBy(sortBy string, sortByWasSet bool) ResultOption

SortBy is a result option to set the sort by field.

func SortOrder

func SortOrder(sortOrder string, sortOrderWasSet bool) ResultOption

SortOrder is a result option to set the sort order direction (asc or desc).

func TableColumns

func TableColumns(tableCols ...string) ResultOption

TableColumns is a result option to set the table column output.

func WideColumns

func WideColumns(wideCols ...string) ResultOption

WideColumns is a result option to set the wide column output.

func YamlName

func YamlName(yamlName string) ResultOption

YamlName is a result option to set the yaml key used for yaml output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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