progresses on #19

This commit is contained in:
Henrique Dias
2015-09-27 13:20:05 +01:00
parent 1062c30911
commit 77b3713fc1
5 changed files with 55 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
package config
import (
"strconv"
"strings"
"github.com/mholt/caddy/config/setup"
@@ -8,15 +9,15 @@ import (
// Config is the add-on configuration set on Caddyfile
type Config struct {
Styles string
Flags []string
Styles string
Hugo bool
Args []string
Command string
}
// ParseHugo parses the configuration file
func ParseHugo(c *setup.Controller) (*Config, error) {
conf := &Config{
Styles: "",
}
// ParseCMS parses the configuration file
func ParseCMS(c *setup.Controller) (*Config, error) {
conf := &Config{Hugo: true}
for c.Next() {
for c.NextBlock() {
@@ -30,9 +31,23 @@ func ParseHugo(c *setup.Controller) (*Config, error) {
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
// Add a beginning slash to make a
conf.Styles = "/" + conf.Styles
case "flags":
conf.Flags = c.RemainingArgs()
if len(conf.Flags) == 0 {
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 {
return conf, c.ArgErr()
}
}
@@ -44,7 +59,7 @@ func ParseHugo(c *setup.Controller) (*Config, error) {
}
func (c *Config) parseFlags() {
for index, element := range c.Flags {
c.Flags[index] = strings.Replace(element, "\"", "", -1)
for index, element := range c.Args {
c.Args[index] = strings.Replace(element, "\"", "", -1)
}
}