summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2016-02-06 23:31:20 +0800
committerAnthony Fok <foka@debian.org>2016-02-06 23:49:45 +0800
commit1f326ad914f749b3558c40c5410b35cb01299ed9 (patch)
treef9974218c25d018166b9d749c5151576a4e3342c /commands
parent45df4596bb065c944c1c16d3c5be8042f64ebba2 (diff)
Fix bash-completion for Hugo builder flags such as --theme
by placing their SetAnnotation() calls after their definitions. See #1824 and 87ca0d0
Diffstat (limited to 'commands')
-rw-r--r--commands/hugo.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index 652e9f040..8a45fbe3c 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -188,26 +188,23 @@ func AddCommands() {
}
// 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 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
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 @@ func init() {
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{})
}