From 0a4e119bc57f8311e47ce5633ca9fb33c334490c Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 29 Jul 2017 14:26:33 +0100 Subject: [PATCH] Close #172 Former-commit-id: d89982644eb2fde52436a4709227b3c68477bad0 [formerly ecef4fca1df20baff25c87edde6a3165953946e0] [formerly acd3363cf88346c69564ce902d8470a55b2865f0 [formerly 011a154f1f8ba762b3b42d8fb0e63c3eb7f9d993]] Former-commit-id: 925e264736253dbcc1be8e7c31de9ebf2e5d2975 [formerly 23310a7c1fb9208d6519955194b31623bb927209] Former-commit-id: 85e9ae5be30392151a709322c3574ac91dc5b52c --- 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)