| 41 | } |
| 42 | |
| 43 | func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command { |
| 44 | opts := CreateOptions{ |
| 45 | IO: f.IOStreams, |
| 46 | Config: f.Config, |
| 47 | HttpClient: f.HttpClient, |
| 48 | Browser: f.Browser, |
| 49 | } |
| 50 | |
| 51 | cmd := &cobra.Command{ |
| 52 | Use: "create [<filename>... | <pattern>... | -]", |
| 53 | Short: "Create a new gist", |
| 54 | Long: heredoc.Docf(` |
| 55 | Create a new GitHub gist with given contents. |
| 56 | |
| 57 | Gists can be created from one or multiple files. Alternatively, pass %[1]s-%[1]s as |
| 58 | filename to read from standard input. |
| 59 | |
| 60 | By default, gists are secret; use %[1]s--public%[1]s to make publicly listed ones. |
| 61 | `, "`"), |
| 62 | Example: heredoc.Doc(` |
| 63 | # Publish file 'hello.py' as a public gist |
| 64 | $ gh gist create --public hello.py |
| 65 | |
| 66 | # Create a gist with a description |
| 67 | $ gh gist create hello.py -d "my Hello-World program in Python" |
| 68 | |
| 69 | # Create a gist containing several files |
| 70 | $ gh gist create hello.py world.py cool.txt |
| 71 | |
| 72 | # Create a gist containing several files using patterns |
| 73 | $ gh gist create *.md *.txt artifact.* |
| 74 | |
| 75 | # Read from standard input to create a gist |
| 76 | $ gh gist create - |
| 77 | |
| 78 | # Create a gist from output piped from another command |
| 79 | $ cat cool.txt | gh gist create |
| 80 | `), |
| 81 | Args: func(cmd *cobra.Command, args []string) error { |
| 82 | if len(args) > 0 { |
| 83 | return nil |
| 84 | } |
| 85 | if opts.IO.IsStdinTTY() { |
| 86 | return cmdutil.FlagErrorf("no filenames passed and nothing on STDIN") |
| 87 | } |
| 88 | return nil |
| 89 | }, |
| 90 | Aliases: []string{"new"}, |
| 91 | RunE: func(c *cobra.Command, args []string) error { |
| 92 | opts.Filenames = args |
| 93 | |
| 94 | if runF != nil { |
| 95 | return runF(&opts) |
| 96 | } |
| 97 | return createRun(&opts) |
| 98 | }, |
| 99 | } |
| 100 | |