Documentation ¶
Overview ¶
Package cmd contains the core logic of commuter.
Index ¶
Constants ¶
const ( // MsgGoogleMapsAPIKeyPrompt is used to prompt the user to enter their Google Maps API Key. MsgGoogleMapsAPIKeyPrompt = promptPrefix + "Enter Google Maps API Key: (developers.google.com/console)" // MsgDefaultLocationPrompt is used to prompt the user to enter their default location. MsgDefaultLocationPrompt = promptPrefix + "Enter Your Default Location: (ex. 123 Main St. Toronto, Canada)" )
const ( // DefaultLocationAlias is the name of the default alias // used for 'From' addresses when one is not provided. DefaultLocationAlias = "default" )
Variables ¶
var ( // ErrAddNameMissing is returned when running the add command the the -name arugment is missing. ErrAddNameMissing = errors.New("missing -name parameter") // ErrAddLocationMissing is returned when running the add command the the -location arugment is missing. ErrAddLocationMissing = errors.New("missing -location parameter") )
var ( // ErrDefaultFromMissing is returned when running the default command and the -from argument is missing. ErrDefaultFromMissing = errors.New("missing -from or -from-current parameter") // ErrDefaultToMissing is returned when running the default command and the -to argument is missing. ErrDefaultToMissing = errors.New("missing -to or -to-current parameter") // ErrNoCommuteMethod is returned when no commute method is selected. ErrNoCommuteMethod = errors.New("at least one commute method must be specified") // ErrFromAndFromCurrentProvided is returned when the -from and -from-current arguments are both supplied. ErrFromAndFromCurrentProvided = errors.New("cannot use -from and -from-current arguments") // ErrToAndToCurrentProvided is returned when the -to and -to-current arguments are both supplied. ErrToAndToCurrentProvided = errors.New("cannot use -to and -to-current arguments") )
Functions ¶
This section is empty.
Types ¶
type AddCmd ¶
type AddCmd struct { Name string Value string Store StorageProvider }
AddCmd represents a command to add a named location.
func (*AddCmd) Run ¶
func (a *AddCmd) Run(conf *Configuration, i Indicator) error
Run adds the named location, overwriting the existing value if necessary.
func (*AddCmd) Validate ¶
func (a *AddCmd) Validate(conf *Configuration) error
Validate validates the AddCmd is properly initialized and ready to be Run.
type CommuteCmd ¶
type CommuteCmd struct { From string FromCurrent bool To string ToCurrent bool Drive bool Walk bool Bike bool Transit bool Durationer Durationer Locator Locator }
CommuteCmd represents the standard command to retrieve the commute time between two locations.
func (*CommuteCmd) Run ¶
func (c *CommuteCmd) Run(conf *Configuration, i Indicator) error
Run calculates the distance between the From and To locations, and outputs the result.
func (*CommuteCmd) String ¶
func (c *CommuteCmd) String() string
String returns a string representation of the CommuteCmd.
func (*CommuteCmd) Validate ¶
func (c *CommuteCmd) Validate(conf *Configuration) (err error)
Validate validates the CommuteCmd is properly initialized and ready to be Run.
type Configuration ¶
Configuration represents a Commuter configuration, including the Google Maps API Key and location map.
func NewConfiguration ¶
func NewConfiguration(s StorageProvider) *Configuration
NewConfiguration attempts to retrieve a Configuration from a storage Provider.
If an error occurs, the configuration is assumed to be corrupted and a nil Configuration is returned.
type ConfigureCmd ¶
type ConfigureCmd struct { Input Scanner Store StorageProvider }
ConfigureCmd is used to configure the commuter application
func (*ConfigureCmd) Run ¶
func (c *ConfigureCmd) Run(conf *Configuration, i Indicator) error
Run prompts the user to configure the commuter application.
func (*ConfigureCmd) String ¶
func (c *ConfigureCmd) String() string
String returns a string representation of the ConfigureCmd.
func (*ConfigureCmd) Validate ¶
func (c *ConfigureCmd) Validate(conf *Configuration) error
Validate validates the ConfigureCmd is properly initialized and ready to be Run.
type Durationer ¶
Durationer provides the ability to retrieve the duration between two locations.
type Indicator ¶
type Indicator interface {
Indicate(string, ...interface{})
}
Indicator defines a type that can provide UI indications to the user.
type ListCmd ¶
type ListCmd struct{}
ListCmd represents a request to list all locations.
func (*ListCmd) Run ¶
func (l *ListCmd) Run(conf *Configuration, i Indicator) error
Run lists all named aliases and their value.
func (*ListCmd) Validate ¶
func (l *ListCmd) Validate(conf *Configuration) error
Validate ensures the ListCmd is valid to be executed.
type Locator ¶
Locator provides the ability to retrieve the current location as a Latitude and Longitude.
type Runner ¶
type Runner interface {
Run(*Configuration, Indicator) error
}
Runner defines a type that can be Run.
type RunnerValidator ¶
RunnerValidator defines a type that can be Run and Validated.
type StorageProvider ¶
StorageProvider defines a type that can be used for storage.
type Validator ¶
type Validator interface {
Validate(*Configuration) error
}
Validator defines a type that can be validated.