add commands to setup #24

This commit is contained in:
Henrique Dias 2016-08-21 19:07:33 +01:00
parent 95262b4289
commit f9f21cbe0c

View File

@ -25,8 +25,8 @@ type Config struct {
// UserConfig contains the configuration for each user // UserConfig contains the configuration for each user
type UserConfig struct { type UserConfig struct {
PathScope string PathScope string // Path the user have access
Root http.FileSystem Root http.FileSystem // The virtual file system the user have access
StyleSheet string // Costum stylesheet StyleSheet string // Costum stylesheet
FrontMatter string // Default frontmatter to save files in FrontMatter string // Default frontmatter to save files in
AllowNew bool // Can create files and folders AllowNew bool // Can create files and folders
@ -69,6 +69,10 @@ func Parse(c *caddy.Controller) ([]Config, error) {
cfg.FrontMatter = "yaml" cfg.FrontMatter = "yaml"
cfg.HugoEnabled = false cfg.HugoEnabled = false
cfg.Users = map[string]*UserConfig{} cfg.Users = map[string]*UserConfig{}
cfg.AllowCommands = true
cfg.AllowEdit = true
cfg.AllowNew = true
cfg.Commands = []string{"git", "svn", "hg"}
baseURL = "" baseURL = ""
cCfg = cfg.UserConfig cCfg = cfg.UserConfig
@ -124,7 +128,7 @@ func Parse(c *caddy.Controller) ([]Config, error) {
if err != nil { if err != nil {
return configs, err return configs, err
} }
case "allow_comands": case "allow_commands":
if !c.NextArg() { if !c.NextArg() {
return configs, c.ArgErr() return configs, c.ArgErr()
} }
@ -132,6 +136,70 @@ func Parse(c *caddy.Controller) ([]Config, error) {
if err != nil { if err != nil {
return configs, err return configs, err
} }
case "allow_command":
if !c.NextArg() {
return configs, c.ArgErr()
}
cCfg.Commands = append(cCfg.Commands, c.Val())
case "block_command":
if !c.NextArg() {
return configs, c.ArgErr()
}
index := 0
for i, val := range cCfg.Commands {
if val == c.Val() {
index = i
}
}
cCfg.Commands = append(cCfg.Commands[:index], cCfg.Commands[index+1:]...)
case "allow":
if !c.NextArg() {
return configs, c.ArgErr()
}
cCfg.Rules = append(cCfg.Rules, &Rule{
Regex: false,
Allow: true,
Path: c.Val(),
Rexexp: nil,
})
case "allow_r":
if !c.NextArg() {
return configs, c.ArgErr()
}
cCfg.Rules = append(cCfg.Rules, &Rule{
Regex: true,
Allow: true,
Path: "",
Rexexp: regexp.MustCompile(c.Val()),
})
case "block":
if !c.NextArg() {
return configs, c.ArgErr()
}
cCfg.Rules = append(cCfg.Rules, &Rule{
Regex: false,
Allow: false,
Path: c.Val(),
Rexexp: nil,
})
case "block_r":
if !c.NextArg() {
return configs, c.ArgErr()
}
cCfg.Rules = append(cCfg.Rules, &Rule{
Regex: true,
Allow: false,
Path: "",
Rexexp: regexp.MustCompile(c.Val()),
})
// NEW USER BLOCK? // NEW USER BLOCK?
default: default:
val := c.Val() val := c.Val()
@ -143,10 +211,22 @@ func Parse(c *caddy.Controller) ([]Config, error) {
// Get the username, sets the current user, and initializes it // Get the username, sets the current user, and initializes it
val = strings.TrimSuffix(val, ":") val = strings.TrimSuffix(val, ":")
cfg.Users[val] = &UserConfig{} cfg.Users[val] = &UserConfig{}
// Initialize the new user
cCfg = cfg.Users[val] cCfg = cfg.Users[val]
cCfg.AllowCommands = cfg.AllowCommands
cCfg.AllowEdit = cfg.AllowEdit
cCfg.AllowNew = cfg.AllowEdit
cCfg.Commands = cfg.Commands
cCfg.FrontMatter = cfg.FrontMatter
cCfg.PathScope = cfg.PathScope
cCfg.Root = cfg.Root
cCfg.Rules = cfg.Rules
cCfg.StyleSheet = cfg.StyleSheet
} }
} }
// Set global base url
cfg.BaseURL = baseURL cfg.BaseURL = baseURL
cfg.BaseURL = strings.TrimPrefix(cfg.BaseURL, "/") cfg.BaseURL = strings.TrimPrefix(cfg.BaseURL, "/")
cfg.BaseURL = strings.TrimSuffix(cfg.BaseURL, "/") cfg.BaseURL = strings.TrimSuffix(cfg.BaseURL, "/")
@ -160,6 +240,10 @@ func Parse(c *caddy.Controller) ([]Config, error) {
if err := appendConfig(cfg); err != nil { if err := appendConfig(cfg); err != nil {
return configs, err return configs, err
} }
fmt.Println(cfg.UserConfig)
fmt.Println(cfg.Users["user1"])
fmt.Println(cfg.Users["user2"])
} }
return configs, nil return configs, nil