Ability to config layout and content dir via cli

fixes spf13/hugo#1598
This commit is contained in:
John Ku 2015-12-08 22:45:24 -08:00 committed by Bjørn Erik Pedersen
parent cafb784799
commit 0ab4162413

View file

@ -143,6 +143,8 @@ var (
var ( var (
baseURL string baseURL string
cacheDir string cacheDir string
contentDir string
layoutDir string
cfgFile string cfgFile string
destination string destination string
logFile string logFile string
@ -213,6 +215,8 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&disableSitemap, "disableSitemap", false, "Do not build Sitemap file") cmd.Flags().BoolVar(&disableSitemap, "disableSitemap", false, "Do not build Sitemap file")
cmd.Flags().BoolVar(&disableRobotsTXT, "disableRobotsTXT", false, "Do not build Robots TXT file") cmd.Flags().BoolVar(&disableRobotsTXT, "disableRobotsTXT", false, "Do not build Robots TXT file")
cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from") cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
cmd.Flags().StringVarP(&contentDir, "contentDir", "c", "", "filesystem path to content directory")
cmd.Flags().StringVarP(&layoutDir, "layoutDir", "l", "", "filesystem path to layout directory")
cmd.Flags().StringVarP(&cacheDir, "cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/") cmd.Flags().StringVarP(&cacheDir, "cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
cmd.Flags().BoolVarP(&ignoreCache, "ignoreCache", "", false, "Ignores the cache directory for reading but still writes to it") cmd.Flags().BoolVarP(&ignoreCache, "ignoreCache", "", false, "Ignores the cache directory for reading but still writes to it")
cmd.Flags().StringVarP(&destination, "destination", "d", "", "filesystem path to write files to") cmd.Flags().StringVarP(&destination, "destination", "d", "", "filesystem path to write files to")
@ -405,6 +409,14 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error {
viper.Set("WorkingDir", dir) viper.Set("WorkingDir", dir)
} }
if contentDir != "" {
viper.Set("ContentDir", contentDir)
}
if layoutDir != "" {
viper.Set("LayoutDir", layoutDir)
}
if cacheDir != "" { if cacheDir != "" {
if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] { if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
cacheDir = cacheDir + helpers.FilePathSeparator cacheDir = cacheDir + helpers.FilePathSeparator