From 011a154f1f8ba762b3b42d8fb0e63c3eb7f9d993 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 29 Jul 2017 14:26:33 +0100 Subject: [PATCH] Close #172 --- cmd/filemanager/main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/filemanager/main.go b/cmd/filemanager/main.go index 1c392d77..8779b0f3 100644 --- a/cmd/filemanager/main.go +++ b/cmd/filemanager/main.go @@ -12,6 +12,8 @@ import ( lumberjack "gopkg.in/natefinch/lumberjack.v2" + "github.com/hacdias/filemanager/plugins" + "github.com/hacdias/filemanager" "github.com/hacdias/fileutils" flag "github.com/spf13/pflag" @@ -25,6 +27,7 @@ var ( scope string commands string logfile string + plugin string port int allowCommands bool allowEdit bool @@ -42,6 +45,7 @@ func init() { flag.BoolVar(&allowCommands, "allow-commands", true, "Default allow commands option for new users") flag.BoolVar(&allowEdit, "allow-edit", true, "Default allow edit option for new users") flag.BoolVar(&allowNew, "allow-new", true, "Default allow new option for new users") + flag.StringVar(&plugin, "plugin", "", "Plugin you want to enable") } func setupViper() { @@ -54,6 +58,7 @@ func setupViper() { viper.SetDefault("AllowCommmands", true) viper.SetDefault("AllowEdit", true) viper.SetDefault("AllowNew", true) + viper.SetDefault("Plugin", "") viper.BindPFlag("Port", flag.Lookup("port")) viper.BindPFlag("Address", flag.Lookup("address")) @@ -64,6 +69,7 @@ func setupViper() { viper.BindPFlag("AllowCommands", flag.Lookup("allow-commands")) viper.BindPFlag("AllowEdit", flag.Lookup("allow-edit")) viper.BindPFlag("AlowNew", flag.Lookup("allow-new")) + viper.BindPFlag("Plugin", flag.Lookup("plugin")) viper.SetConfigName("filemanager") viper.AddConfigPath(".") @@ -118,6 +124,25 @@ func main() { log.Fatal(err) } + if viper.GetString("Plugin") == "hugo" { + // Initialize the default settings for Hugo. + hugo := &plugins.Hugo{ + Root: viper.GetString("Scope"), + Public: filepath.Join(viper.GetString("Scope"), "public"), + Args: []string{}, + CleanPublic: true, + } + + // Try to find the Hugo executable path. + if err = hugo.Find(); err != nil { + log.Fatal(err) + } + + if err = fm.ActivatePlugin("hugo", hugo); err != nil { + log.Fatal(err) + } + } + // Builds the address and a listener. laddr := viper.GetString("Address") + ":" + viper.GetString("Port") listener, err := net.Listen("tcp", laddr)