mirror of
https://hacklab.nilfm.cc/nirvash
synced 2024-10-22 14:01:49 +00:00
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"nilfm.cc/git/quartzgun/auth"
|
||
|
"nilfm.cc/git/nirvash/config"
|
||
|
)
|
||
|
|
||
|
func Process(args []string, userStore auth.UserStore, cfg *config.Config) bool {
|
||
|
if len(args) == 1 {
|
||
|
return false
|
||
|
}
|
||
|
switch args[1] {
|
||
|
case "adduser":
|
||
|
if len(args) < 4 {
|
||
|
return help()
|
||
|
}
|
||
|
userStore.AddUser(args[2], args[3])
|
||
|
case "rmuser":
|
||
|
if len(args) < 3 {
|
||
|
return help()
|
||
|
}
|
||
|
userStore.DeleteUser(args[2])
|
||
|
case "passwd":
|
||
|
if len(args) < 5 {
|
||
|
return help()
|
||
|
}
|
||
|
userStore.ChangePassword(args[2], args[3], args[4])
|
||
|
case "configure":
|
||
|
fmt.Printf("configuring\n")
|
||
|
for _, token := range args[2:] {
|
||
|
kvp := strings.Split(token, "=")
|
||
|
k := kvp[0]
|
||
|
v := kvp[1]
|
||
|
fmt.Printf("%s = %s\n", k, v)
|
||
|
switch k {
|
||
|
case "adapter":
|
||
|
config.SetAdapter(cfg, v)
|
||
|
case "root":
|
||
|
cfg.Root = v
|
||
|
case "assetRoot":
|
||
|
cfg.AssetRoot = v
|
||
|
case "staticRoot":
|
||
|
cfg.StaticRoot = v
|
||
|
case "plugins":
|
||
|
// handle plugins later
|
||
|
default:
|
||
|
panic("unknown configuration option: " + v)
|
||
|
}
|
||
|
}
|
||
|
config.Write(cfg)
|
||
|
default:
|
||
|
help()
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func help() bool {
|
||
|
return true
|
||
|
}
|