@@ -23,9 +23,10 @@ import (
2323type CreateOptions struct {
2424 IO * iostreams.IOStreams
2525
26- Description string
27- Public bool
28- Filenames []string
26+ Description string
27+ Public bool
28+ Filenames []string
29+ FilenameOverride string
2930
3031 HttpClient func () (* http.Client , error )
3132}
@@ -84,6 +85,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
8485
8586 cmd .Flags ().StringVarP (& opts .Description , "desc" , "d" , "" , "A description for this gist" )
8687 cmd .Flags ().BoolVarP (& opts .Public , "public" , "p" , false , "List the gist publicly (default: private)" )
88+ cmd .Flags ().StringVarP (& opts .FilenameOverride , "filename" , "f" , "" , "Provide a filename to be used when reading from STDIN" )
8789 return cmd
8890}
8991
@@ -93,7 +95,7 @@ func createRun(opts *CreateOptions) error {
9395 fileArgs = []string {"-" }
9496 }
9597
96- files , err := processFiles (opts .IO .In , fileArgs )
98+ files , err := processFiles (opts .IO .In , opts . FilenameOverride , fileArgs )
9799 if err != nil {
98100 return fmt .Errorf ("failed to collect files for posting: %w" , err )
99101 }
@@ -137,7 +139,7 @@ func createRun(opts *CreateOptions) error {
137139 return nil
138140}
139141
140- func processFiles (stdin io.ReadCloser , filenames []string ) (map [string ]string , error ) {
142+ func processFiles (stdin io.ReadCloser , filenameOverride string , filenames []string ) (map [string ]string , error ) {
141143 fs := map [string ]string {}
142144
143145 if len (filenames ) == 0 {
@@ -149,7 +151,11 @@ func processFiles(stdin io.ReadCloser, filenames []string) (map[string]string, e
149151 var content []byte
150152 var err error
151153 if f == "-" {
152- filename = fmt .Sprintf ("gistfile%d.txt" , i )
154+ if filenameOverride != "" {
155+ filename = filenameOverride
156+ } else {
157+ filename = fmt .Sprintf ("gistfile%d.txt" , i )
158+ }
153159 content , err = ioutil .ReadAll (stdin )
154160 if err != nil {
155161 return fs , fmt .Errorf ("failed to read from stdin: %w" , err )
0 commit comments