Adds a few convenience methods to the Entry type
This commit is contained in:
parent
7ac598e5dc
commit
af14a9f84f
22
mailcap.go
22
mailcap.go
|
@ -137,6 +137,28 @@ func (e Entry) SetAction(action string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Retrieve the command for a particular action as a string.
|
||||
// The string will not have a path inserted into it and will have
|
||||
// %s to represent the place that the path will go.
|
||||
func (e Entry) GetCommand(action string) (string, error) {
|
||||
if v, ok := e[action]; ok {
|
||||
return v, nil
|
||||
}
|
||||
return "", fmt.Errorf("This entry does not have the action %q available", action)
|
||||
}
|
||||
|
||||
// Get the available actions/attributes for an entry as
|
||||
// a string slice
|
||||
func (e Entry) Actions() []string {
|
||||
o := make([]string, len(e))
|
||||
i := 0
|
||||
for k, _ := range e {
|
||||
o[i] = k
|
||||
i++
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Look up all of the Entry types available for
|
||||
// a given mime and key. Returns an Entry slice (Fields)
|
||||
func (m *Mailcap) lookup(mime, key string) Entries {
|
||||
|
|
Loading…
Reference in New Issue