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

38 lines
1000 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 {
2017-07-25 15:29:38 +02:00
// these are pointers so we can tell whether they've been set, and leave
// the config file alone if not
Destination, Host *string
Drafts, Future, Unpublished *bool
Incremental, Verbose *bool
Port *int
// these aren't in the config file, so make them actual values
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) {
2017-07-25 15:29:38 +02:00
// anything you can do I can do meta
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
}