ref: 1f326ad914f749b3558c40c5410b35cb01299ed9
parent: 45df4596bb065c944c1c16d3c5be8042f64ebba2
author: Anthony Fok <[email protected]>
date: Sat Feb 6 18:31:20 EST 2016
Fix bash-completion for Hugo builder flags such as --theme by placing their SetAnnotation() calls after their definitions. See #1824 and 87ca0d0
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -188,26 +188,23 @@
}
// initHugoBuilderFlags initializes all common flags, typically used by the
-// core build commands.
+// core build commands, namely hugo itself, server, check and benchmark.
func initHugoBuilderFlags(cmd *cobra.Command) {
initCoreCommonFlags(cmd)
initHugoBuildCommonFlags(cmd)
}
-// initCoreCommonFlags initializes common flags used by Hugo core commands
-// such as hugo itself, server, check, config and benchmark.
+// initCoreCommonFlags initializes common flags used by Hugo core commands.
func initCoreCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
- // For bash-completion
+
+ // Set bash-completion
validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
- cmd.Flags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
- cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
- cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
- cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}
-// initial flags related to the Hugo build
+// initHugoBuildCommonFlags initialize common flags related to the Hugo build.
+// Called by initHugoBuilderFlags.
func initHugoBuildCommonFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&cleanDestination, "cleanDestinationDir", false, "Remove files from destination not found in static directories")
cmd.Flags().BoolVarP(&draft, "buildDrafts", "D", false, "include content marked as draft")
@@ -230,6 +227,12 @@
cmd.Flags().BoolVarP(&forceSync, "forceSyncStatic", "", false, "Copy all files when static is changed.")
cmd.Flags().BoolVarP(&noTimes, "noTimes", "", false, "Don't sync modification time of files")
+ // Set bash-completion.
+ // Each flag must first be defined before using the SetAnnotation() call.
+ cmd.Flags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
+ cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
+ cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
+ cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}
func initBenchmarkBuildingFlags(cmd *cobra.Command) {
@@ -249,7 +252,7 @@
HugoCmd.Flags().BoolVarP(&buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
hugoCmdV = HugoCmd
- // For bash-completion
+ // Set bash-completion
HugoCmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
}