Enable dirname and filename completion for more flags
authorAnthony Fok <foka@debian.org>
Wed, 2 Dec 2015 09:20:55 +0000 (02:20 -0700)
committerAnthony Fok <foka@debian.org>
Wed, 2 Dec 2015 09:24:49 +0000 (02:24 -0700)
These flags are:

 * --source (-s), --cacheDir, --destination (-d) and --logFile
 * --completionfile and --dir.

commands/genautocomplete.go
commands/gendoc.go
commands/genman.go
commands/hugo.go

index 2a2fcdd91206809a470aebeb097a5e4b2ffcb510..b7f74fd89ddc84e3452999e10cf5952572a240ea 100644 (file)
@@ -48,4 +48,6 @@ func init() {
        genautocompleteCmd.PersistentFlags().StringVarP(&autocompleteTarget, "completionfile", "", "/etc/bash_completion.d/hugo.sh", "Autocompletion file")
        genautocompleteCmd.PersistentFlags().StringVarP(&autocompleteType, "type", "", "bash", "Autocompletion type (currently only bash supported)")
 
+       // For bash-completion
+       genautocompleteCmd.PersistentFlags().SetAnnotation("completionfile", cobra.BashCompFilenameExt, []string{})
 }
index ed7f073ac98879ab21b39a6e55837096576f50b5..9589bffa4550af94de48302425fa6591f2aeaea1 100644 (file)
@@ -60,4 +60,7 @@ for rendering in Hugo.`,
 
 func init() {
        gendocCmd.PersistentFlags().StringVar(&gendocdir, "dir", "/tmp/hugodoc/", "the directory to write the doc.")
+
+       // For bash-completion
+       gendocCmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
 }
index 3dc8d3f52e4145985f97282d326ccb9778458b18..68a98a46d29d1554f2f89e3ce7a47754923f67c0 100644 (file)
@@ -42,4 +42,7 @@ in the "man" directory under the current directory.`,
 
 func init() {
        genmanCmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
+
+       // For bash-completion
+       genmanCmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
 }
index ea81797800aa7e2f5c30f9605a49263b74e0b60b..2a72f535ef0e841be1d5d4ccd10d658b9c2454cd 100644 (file)
@@ -123,10 +123,14 @@ func init() {
        HugoCmd.Flags().BoolVarP(&NoTimes, "noTimes", "", false, "Don't sync modification time of files")
        hugoCmdV = HugoCmd
 
-       // for Bash autocomplete
+       // For bash-completion
        validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
        HugoCmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
+       HugoCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
+       HugoCmd.PersistentFlags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
+       HugoCmd.PersistentFlags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
        HugoCmd.PersistentFlags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
+       HugoCmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
 
        // This message will be shown to Windows users if Hugo is opened from explorer.exe
        cobra.MousetrapHelpText = `