From 48b95d059436b6e8db2082d1d6e3192c8eabe1dd Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 4 May 2015 16:20:06 -0400 Subject: [PATCH] Make the filename extension bit of docs easier to read. --- bash_completions.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bash_completions.md b/bash_completions.md index e1a5d56..f6707ff 100644 --- a/bash_completions.md +++ b/bash_completions.md @@ -123,15 +123,18 @@ and you'll get something like In this example we use --filename= and expect to get a json or yaml file as the argument. To make this easier we annotate the --filename flag with valid filename extensions. ```go - annotations := make([]string, 3) - annotations[0] = "json" - annotations[1] = "yaml" - annotations[2] = "yml" - + annotations := []string{"json", "yaml", "yml"} annotation := make(map[string][]string) annotation[cobra.BashCompFilenameExt] = annotations - flag := &pflag.Flag{"filename", "f", usage, value, value.String(), false, annotation} + flag := &pflag.Flag{ + Name: "filename", + Shorthand: "f", + Usage: usage, + Value: value, + DefValue: value.String(), + Annotations: annotation, + } cmd.Flags().AddFlag(flag) ```