| 42 | } |
| 43 | |
| 44 | func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Command { |
| 45 | opts := EditOptions{ |
| 46 | IO: f.IOStreams, |
| 47 | HttpClient: f.HttpClient, |
| 48 | Config: f.Config, |
| 49 | Prompter: f.Prompter, |
| 50 | Edit: func(editorCmd, filename, defaultContent string, io *iostreams.IOStreams) (string, error) { |
| 51 | return surveyext.Edit( |
| 52 | editorCmd, |
| 53 | "*."+filename, |
| 54 | defaultContent, |
| 55 | io.In, io.Out, io.ErrOut) |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | cmd := &cobra.Command{ |
| 60 | Use: "edit {<id> | <url>} [<filename>]", |
| 61 | Short: "Edit one of your gists", |
| 62 | Example: heredoc.Doc(` |
| 63 | # Select a gist to edit interactively |
| 64 | $ gh gist edit |
| 65 | |
| 66 | # Edit a gist file in the default editor |
| 67 | $ gh gist edit 1234567890abcdef1234567890abcdef |
| 68 | |
| 69 | # Edit a specific file in the gist |
| 70 | $ gh gist edit 1234567890abcdef1234567890abcdef --filename hello.py |
| 71 | |
| 72 | # Replace a gist file with content from a local file |
| 73 | $ gh gist edit 1234567890abcdef1234567890abcdef --filename hello.py hello.py |
| 74 | |
| 75 | # Add a new file to the gist |
| 76 | $ gh gist edit 1234567890abcdef1234567890abcdef --add newfile.py |
| 77 | |
| 78 | # Change the description of the gist |
| 79 | $ gh gist edit 1234567890abcdef1234567890abcdef --desc "new description" |
| 80 | |
| 81 | # Remove a file from the gist |
| 82 | $ gh gist edit 1234567890abcdef1234567890abcdef --remove hello.py |
| 83 | `), |
| 84 | Args: func(cmd *cobra.Command, args []string) error { |
| 85 | if len(args) > 2 { |
| 86 | return cmdutil.FlagErrorf("too many arguments") |
| 87 | } |
| 88 | return nil |
| 89 | }, |
| 90 | RunE: func(c *cobra.Command, args []string) error { |
| 91 | if len(args) > 0 { |
| 92 | opts.Selector = args[0] |
| 93 | } |
| 94 | if len(args) > 1 { |
| 95 | opts.SourceFile = args[1] |
| 96 | } |
| 97 | |
| 98 | if runF != nil { |
| 99 | return runF(&opts) |
| 100 | } |
| 101 | |