1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:39:01 +01:00
gojekyll/config/flags.go

35 lines
967 B
Go
Raw Normal View History

2017-07-01 21:03:36 +02:00
package config
import (
"reflect"
)
2017-07-01 21:03:36 +02:00
// Flags are applied after the configuration file is loaded.
// They are pointers to represent optional types, to tell whether they have been set.
type Flags struct {
// these are pointers so we can tell whether they've been set, and override
// the config file only if
2017-07-23 17:25:17 +02:00
Destination, Host *string
Drafts, Future, Unpublished, Verbose *bool
Port *int
// these aren't in the config file, so they can be treated more conventionally
2017-07-23 17:25:17 +02:00
DryRun, ForcePolling, Watch bool
2017-07-01 21:03:36 +02:00
}
// ApplyFlags overwrites the configuration with values from flags.
func (c *Config) ApplyFlags(f Flags) {
rs, rd := reflect.ValueOf(f), reflect.ValueOf(c).Elem()
rt := rs.Type()
for i, n := 0, rs.NumField(); i < n; i++ {
field := rt.Field(i)
val := rs.Field(i)
if val.Kind() == reflect.Ptr {
if val.IsNil() {
continue
}
val = val.Elem()
}
rd.FieldByName(field.Name).Set(val)
2017-07-15 00:40:09 +02:00
}
2017-07-01 21:03:36 +02:00
}