From b568e9d6a616c7c496dfd57ef87cc4b3c7b4c85b Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 2 Jan 2019 20:43:35 +0000 Subject: [PATCH] feat: add to CLI License: MIT Signed-off-by: Henrique Dias --- cmd/config.go | 4 ++-- cmd/config_init.go | 2 ++ cmd/config_set.go | 4 ++++ types/settings.go | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 1ea7d518..fd13c741 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -13,8 +13,6 @@ import ( "github.com/spf13/cobra" ) - - func init() { rootCmd.AddCommand(configCmd) } @@ -34,6 +32,7 @@ func addConfigFlags(cmd *cobra.Command) { addUserFlags(cmd) cmd.Flags().StringP("baseURL", "b", "/", "base url of this installation") cmd.Flags().BoolP("signup", "s", false, "allow users to signup") + cmd.Flags().String("shell", "", "shell command to which other commands should be appended") cmd.Flags().String("auth.method", string(auth.MethodJSONAuth), "authentication type") cmd.Flags().String("auth.header", "", "HTTP header for auth.method=proxy") @@ -94,6 +93,7 @@ func printSettings(s *types.Settings, auther types.Auther) { fmt.Fprintf(w, "\nBase URL:\t%s\n", s.BaseURL) fmt.Fprintf(w, "Sign up:\t%t\n", s.Signup) fmt.Fprintf(w, "Auth method:\t%s\n", s.AuthMethod) + fmt.Fprintf(w, "Shell:\t%s\t", strings.Join(s.Shell, " ")) fmt.Fprintln(w, "\nBranding:") fmt.Fprintf(w, "\tName:\t%s\n", s.Branding.Name) fmt.Fprintf(w, "\tFiles override:\t%s\n", s.Branding.Files) diff --git a/cmd/config_init.go b/cmd/config_init.go index c580cf05..0f5be68f 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strings" "github.com/asdine/storm" "github.com/filebrowser/filebrowser/bolt" @@ -40,6 +41,7 @@ override the options.`, Key: generateRandomBytes(64), // 256 bits BaseURL: mustGetString(cmd, "baseURL"), Signup: mustGetBool(cmd, "signup"), + Shell: strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " "), Defaults: defaults, AuthMethod: authMethod, Branding: types.Branding{ diff --git a/cmd/config_set.go b/cmd/config_set.go index d74af6be..488d3a9e 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -1,6 +1,8 @@ package cmd import ( + "strings" + "github.com/filebrowser/filebrowser/types" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -34,6 +36,8 @@ you want to change.`, s.Signup = mustGetBool(cmd, "signup") case "auth.method": auth = true + case "shell": + s.Shell = strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " ") case "branding.name": s.Branding.Name = mustGetString(cmd, "branding.name") case "branding.disableExternal": diff --git a/types/settings.go b/types/settings.go index c4042245..2bcb49cc 100644 --- a/types/settings.go +++ b/types/settings.go @@ -12,7 +12,7 @@ type Settings struct { AuthMethod AuthMethod `json:"authMethod"` Branding Branding `json:"branding"` Commands map[string][]string `json:"commands"` - Shell []string `json:"shell"` // TODO add to cli + Shell []string `json:"shell"` Rules []Rule `json:"rules"` // TODO: use this add to cli }