cmd/root.go
changeset 91 02312ccc1fd3
parent 85 a4464c0b0c36
child 125 d436b88d137b
equal deleted inserted replaced
90:b1da6dc9f689 91:02312ccc1fd3
    44 __madonctl_output() {
    44 __madonctl_output() {
    45 	COMPREPLY=( plain json yaml template theme )
    45 	COMPREPLY=( plain json yaml template theme )
    46 }
    46 }
    47 __madonctl_color() {
    47 __madonctl_color() {
    48 	COMPREPLY=( auto on off )
    48 	COMPREPLY=( auto on off )
       
    49 }
       
    50 __madonctl_theme() {
       
    51 	local madonctl_output out
       
    52 	# This doesn't handle spaces or special chars...
       
    53 	if out=$(madonctl config themes 2>/dev/null); then
       
    54 		COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
       
    55 	fi
    49 }
    56 }
    50 `
    57 `
    51 
    58 
    52 // RootCmd represents the base command when called without any subcommands
    59 // RootCmd represents the base command when called without any subcommands
    53 var RootCmd = &cobra.Command{
    60 var RootCmd = &cobra.Command{
   150 	// Flag completion
   157 	// Flag completion
   151 	annotationOutput := make(map[string][]string)
   158 	annotationOutput := make(map[string][]string)
   152 	annotationOutput[cobra.BashCompCustom] = []string{"__madonctl_output"}
   159 	annotationOutput[cobra.BashCompCustom] = []string{"__madonctl_output"}
   153 	annotationColor := make(map[string][]string)
   160 	annotationColor := make(map[string][]string)
   154 	annotationColor[cobra.BashCompCustom] = []string{"__madonctl_color"}
   161 	annotationColor[cobra.BashCompCustom] = []string{"__madonctl_color"}
       
   162 	annotationTheme := make(map[string][]string)
       
   163 	annotationTheme[cobra.BashCompCustom] = []string{"__madonctl_theme"}
   155 
   164 
   156 	RootCmd.PersistentFlags().Lookup("output").Annotations = annotationOutput
   165 	RootCmd.PersistentFlags().Lookup("output").Annotations = annotationOutput
   157 	RootCmd.PersistentFlags().Lookup("color").Annotations = annotationColor
   166 	RootCmd.PersistentFlags().Lookup("color").Annotations = annotationColor
       
   167 	RootCmd.PersistentFlags().Lookup("theme").Annotations = annotationTheme
   158 }
   168 }
   159 
   169 
   160 // initConfig reads in config file and ENV variables if set.
   170 // initConfig reads in config file and ENV variables if set.
   161 func initConfig() {
   171 func initConfig() {
   162 	if cfgFile != "" { // enable ability to specify config file via flag
   172 	if cfgFile != "" { // enable ability to specify config file via flag