| 205 | } |
| 206 | |
| 207 | func shellCompletionCmd() *cobra.Command { |
| 208 | |
| 209 | cmd := &cobra.Command{ |
| 210 | |
| 211 | Use: "completion", |
| 212 | Short: "Generates shell completion scripts for bash or zsh", |
| 213 | Annotations: map[string]string{"group": "tool"}, |
| 214 | } |
| 215 | cmd.SetHelpTemplate(x.NonRootTemplate) |
| 216 | |
| 217 | // bash subcommand |
| 218 | cmd.AddCommand(&cobra.Command{ |
| 219 | Use: "bash", |
| 220 | Short: "bash shell completion", |
| 221 | Long: `To load bash completion run: |
| 222 | dgraph completion bash > dgraph-completion.sh |
| 223 | |
| 224 | To configure your bash shell to load completions for each session, |
| 225 | add to your bashrc: |
| 226 | |
| 227 | # ~/.bashrc or ~/.profile |
| 228 | . path/to/dgraph-completion.sh |
| 229 | `, |
| 230 | Args: cobra.NoArgs, |
| 231 | RunE: func(cmd *cobra.Command, args []string) error { |
| 232 | return RootCmd.GenBashCompletion(os.Stdout) |
| 233 | }, |
| 234 | }) |
| 235 | |
| 236 | // zsh subcommand |
| 237 | cmd.AddCommand(&cobra.Command{ |
| 238 | Use: "zsh", |
| 239 | Short: "zsh shell completion", |
| 240 | Long: `To generate zsh completion run: |
| 241 | dgraph completion zsh > _dgraph |
| 242 | |
| 243 | Then install the completion file somewhere in your $fpath or |
| 244 | $_compdir paths. You must enable the compinit and compinstall plugins. |
| 245 | |
| 246 | For more information, see the official Zsh docs: |
| 247 | http://zsh.sourceforge.net/Doc/Release/Completion-System.html |
| 248 | `, |
| 249 | Args: cobra.NoArgs, |
| 250 | RunE: func(cmd *cobra.Command, args []string) error { |
| 251 | return RootCmd.GenZshCompletion(os.Stdout) |
| 252 | }, |
| 253 | }) |
| 254 | |
| 255 | return cmd |
| 256 | |
| 257 | } |
| 258 | |
| 259 | // convertJSON converts JSON hierarchical config objects into a flattened map fulfilling the |
| 260 | // z.SuperFlag string format so that Viper can correctly set z.SuperFlag config options for the |