Skip to content

Commit 666ddd2

Browse files
committed
Enable dirname and filename completion for more flags
These flags are: * --source (-s), --cacheDir, --destination (-d) and --logFile * --completionfile and --dir.
1 parent 0d1d33d commit 666ddd2

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

‎commands/genautocomplete.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ func init() {
4848
genautocompleteCmd.PersistentFlags().StringVarP(&autocompleteTarget, "completionfile", "", "/etc/bash_completion.d/hugo.sh", "Autocompletion file")
4949
genautocompleteCmd.PersistentFlags().StringVarP(&autocompleteType, "type", "", "bash", "Autocompletion type (currently only bash supported)")
5050

51+
// For bash-completion
52+
genautocompleteCmd.PersistentFlags().SetAnnotation("completionfile", cobra.BashCompFilenameExt, []string{})
5153
}

‎commands/gendoc.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ for rendering in Hugo.`,
6060

6161
func init() {
6262
gendocCmd.PersistentFlags().StringVar(&gendocdir, "dir", "/tmp/hugodoc/", "the directory to write the doc.")
63+
64+
// For bash-completion
65+
gendocCmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
6366
}

‎commands/genman.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ in the "man" directory under the current directory.`,
4242

4343
func init() {
4444
genmanCmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
45+
46+
// For bash-completion
47+
genmanCmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
4548
}

‎commands/hugo.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ func init() {
123123
HugoCmd.Flags().BoolVarP(&NoTimes, "noTimes", "", false, "Don't sync modification time of files")
124124
hugoCmdV = HugoCmd
125125

126-
// for Bash autocomplete
126+
// For bash-completion
127127
validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
128128
HugoCmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
129+
HugoCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
130+
HugoCmd.PersistentFlags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
131+
HugoCmd.PersistentFlags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
129132
HugoCmd.PersistentFlags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
133+
HugoCmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
130134

131135
// This message will be shown to Windows users if Hugo is opened from explorer.exe
132136
cobra.MousetrapHelpText = `

0 commit comments

Comments
 (0)