2015-09-20 08:15:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2015-09-27 12:20:05 +00:00
|
|
|
"strconv"
|
2015-09-20 08:15:21 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/config/setup"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the add-on configuration set on Caddyfile
|
|
|
|
type Config struct {
|
2015-09-27 12:20:05 +00:00
|
|
|
Styles string
|
|
|
|
Hugo bool
|
|
|
|
Args []string
|
|
|
|
Command string
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 12:20:05 +00:00
|
|
|
// ParseCMS parses the configuration file
|
|
|
|
func ParseCMS(c *setup.Controller) (*Config, error) {
|
|
|
|
conf := &Config{Hugo: true}
|
2015-09-20 08:15:21 +00:00
|
|
|
|
|
|
|
for c.Next() {
|
|
|
|
for c.NextBlock() {
|
|
|
|
switch c.Val() {
|
|
|
|
case "styles":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Styles = c.Val()
|
|
|
|
// Remove the beginning slash if it exists or not
|
|
|
|
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
|
|
|
// Add a beginning slash to make a
|
|
|
|
conf.Styles = "/" + conf.Styles
|
2015-09-27 12:20:05 +00:00
|
|
|
case "hugo":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
conf.Hugo, err = strconv.ParseBool(c.Val())
|
|
|
|
if err != nil {
|
|
|
|
return conf, err
|
|
|
|
}
|
|
|
|
case "command":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Command = c.Val()
|
|
|
|
case "args":
|
|
|
|
conf.Args = c.RemainingArgs()
|
|
|
|
if len(conf.Args) == 0 {
|
2015-09-20 21:00:25 +00:00
|
|
|
return conf, c.ArgErr()
|
|
|
|
}
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-20 21:00:25 +00:00
|
|
|
conf.parseFlags()
|
2015-09-20 08:15:21 +00:00
|
|
|
return conf, nil
|
|
|
|
}
|
2015-09-20 21:00:25 +00:00
|
|
|
|
|
|
|
func (c *Config) parseFlags() {
|
2015-09-27 12:20:05 +00:00
|
|
|
for index, element := range c.Args {
|
|
|
|
c.Args[index] = strings.Replace(element, "\"", "", -1)
|
2015-09-20 21:00:25 +00:00
|
|
|
}
|
|
|
|
}
|