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