shithub: hugo

Download patch

ref: 27a524b0905ec73c1eef233f94700feb9f465011
parent: bede93de005dcf934f3ec9be6388310ac6c57acd
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Apr 14 06:34:02 EDT 2018

commands: Properly handle CLI slice arguments

Like `--disableKinds` -- this handling was kind of broken when we recently moved this from global vars

See #4607

--- a/commands/commands_test.go
+++ b/commands/commands_test.go
@@ -57,8 +57,10 @@
 	}{{[]string{"server",
 		"--config=myconfig.toml",
 		"--contentDir=mycontent",
+		"--disableKinds=page,home",
 		"--layoutDir=mylayouts",
 		"--theme=mytheme",
+		"--gc",
 		"--themesDir=mythemes",
 		"--cleanDestinationDir",
 		"--navigateToChanged",
@@ -100,7 +102,10 @@
 		assert.Equal("mytheme", cfg.GetString("theme"))
 		assert.Equal("mythemes", cfg.GetString("themesDir"))
 
+		assert.Equal([]string{"page", "home"}, cfg.Get("disableKinds"))
+
 		assert.True(cfg.GetBool("uglyURLs"))
+		assert.True(cfg.GetBool("gc"))
 
 		// The flag is named i18n-warnings
 		assert.True(cfg.GetBool("logI18nWarnings"))
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -243,7 +243,20 @@
 		if targetKey != "" {
 			configKey = targetKey
 		}
-		cfg.Set(configKey, f.Value.String())
+		// Gotta love this API.
+		switch f.Value.Type() {
+		case "bool":
+			bv, _ := flags.GetBool(key)
+			cfg.Set(configKey, bv)
+		case "string":
+			cfg.Set(configKey, f.Value.String())
+		case "stringSlice":
+			bv, _ := flags.GetStringSlice(key)
+			cfg.Set(configKey, bv)
+		default:
+			panic(fmt.Sprintf("update switch with %s", f.Value.Type()))
+		}
+
 	}
 }