forked from TrueCloudLab/rclone
cmd/providers: add DefaultStr, ValueStr and Type fields
These fields are auto generated: - DefaultStr - a string rendering of Default - ValueStr - a string rendering of Value - Type - the type of the option
This commit is contained in:
parent
e2b6172f7d
commit
ac4c8d8dfc
1 changed files with 24 additions and 0 deletions
24
fs/fs.go
24
fs/fs.go
|
@ -2,6 +2,7 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -132,6 +133,29 @@ type Option struct {
|
|||
Advanced bool // set if this is an advanced config option
|
||||
}
|
||||
|
||||
// BaseOption is an alias for Option used internally
|
||||
type BaseOption Option
|
||||
|
||||
// MarshalJSON turns an Option into JSON
|
||||
//
|
||||
// It adds some generated fields for ease of use
|
||||
// - DefaultStr - a string rendering of Default
|
||||
// - ValueStr - a string rendering of Value
|
||||
// - Type - the type of the option
|
||||
func (o *Option) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(struct {
|
||||
BaseOption
|
||||
DefaultStr string
|
||||
ValueStr string
|
||||
Type string
|
||||
}{
|
||||
BaseOption: BaseOption(*o),
|
||||
DefaultStr: fmt.Sprint(o.Default),
|
||||
ValueStr: o.String(),
|
||||
Type: o.Type(),
|
||||
})
|
||||
}
|
||||
|
||||
// GetValue gets the current current value which is the default if not set
|
||||
func (o *Option) GetValue() interface{} {
|
||||
val := o.Value
|
||||
|
|
Loading…
Reference in a new issue