Make hugo server -t work again
authorAnton Harniakou <anton.harniakou@gmail.com>
Sun, 13 Jan 2019 09:44:38 +0000 (12:44 +0300)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 13 Jan 2019 20:13:59 +0000 (20:13 +0000)
This commit solves an issue where hugo would ignore the cli -t flag
and only use a theme defined in config.toml.

Also allow -t flag to accept a string slice.

Closes #5569
Closes #5061
Related #4868

commands/commands.go
commands/commands_test.go
hugolib/paths/paths.go

index f835e67a1ab342b77723084df55c4d5142b4a4a0..c2fb90830f2ebd7b62ae8f65713c79834a372e81 100644 (file)
@@ -250,7 +250,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
        cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
        cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
        cmd.Flags().StringP("destination", "d", "", "filesystem path to write files to")
-       cmd.Flags().StringP("theme", "t", "", "theme to use (located in /themes/THEMENAME/)")
+       cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
        cmd.Flags().StringP("themesDir", "", "", "filesystem path to themes directory")
        cmd.Flags().StringVarP(&cc.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. http://spf13.com/")
        cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date and author info to the pages")
index a8cc1d92743ef57990f269c402a6ba6802412cce..57c9d6005616d418685adc37549491278eb350ea 100644 (file)
@@ -104,7 +104,7 @@ func TestCommandsPersistentFlags(t *testing.T) {
                assert.Equal("/tmp/mydestination", cfg.GetString("publishDir"))
                assert.Equal("mycontent", cfg.GetString("contentDir"))
                assert.Equal("mylayouts", cfg.GetString("layoutDir"))
-               assert.Equal("mytheme", cfg.GetString("theme"))
+               assert.Equal([]string{"mytheme"}, cfg.GetStringSlice("theme"))
                assert.Equal("mythemes", cfg.GetString("themesDir"))
                assert.Equal("https://example.com/b/", cfg.GetString("baseURL"))
 
index 7de0d9ffea9c31c9d3580af3855f89a3c888e629..df66e2a46e2f6e7d6f33a75b002db3e3120c6c91 100644 (file)
@@ -176,7 +176,7 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
                PaginatePath: cfg.GetString("paginatePath"),
        }
 
-       if cfg.IsSet("allThemes") {
+       if !cfg.IsSet("theme") && cfg.IsSet("allThemes") {
                p.AllThemes = cfg.Get("allThemes").([]ThemeConfig)
        } else {
                p.AllThemes, err = collectThemeNames(p)