MCPcopy Create free account
hub / github.com/cli/cli / NewCmdCreate

Function NewCmdCreate

pkg/cmd/issue/artifact/create/create.go:99–243  ·  view source on GitHub ↗

NewCmdCreate creates the gh issue artifact create command.

(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*CreateOptions) error)

Source from the content-addressed store, hash-verified

97
98// NewCmdCreate creates the gh issue artifact create command.
99func NewCmdCreate(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*CreateOptions) error) *cobra.Command {
100 opts := &CreateOptions{
101 IO: f.IOStreams,
102 HttpClient: f.HttpClient,
103 }
104
105 var body, bodyFile, name string
106
107 cmd := &cobra.Command{
108 Use: "create {<issue-number> | <issue-url>} [<file>[#<name>] | <url>]...",
109 Short: "Create issue artifacts (preview)",
110 Long: heredoc.Docf(`
111 Create one artifact for each file or URL. A text file becomes a document
112 named after the file; add %[1]s#<name>%[1]s to choose a different name. A %[1]s.html%[1]s or
113 %[1]s.htm%[1]s file becomes an HTML document. A URL, or a %[1]s.url%[1]s Internet Shortcut
114 file, becomes a link; a URL is named after its host.
115
116 Artifact names can't contain some characters, such as parentheses. When a
117 file's name has them, they're removed: %[1]splan (1).md%[1]s is named %[1]splan 1.md%[1]s.
118
119 Use %[1]s--body%[1]s to create a single document from text, or %[1]s--body-file%[1]s to create
120 one artifact from a file (%[1]s-%[1]s reads standard input). %[1]s--name%[1]s sets its name.
121
122 Documents are saved as %[1]sgeneric%[1]s, and HTML documents as %[1]sembedded_html%[1]s. Use
123 %[1]s--type%[1]s to set the type of every document instead, whatever the file
124 extension. A plan currently behaves the same as a generic document.
125 `, "`"),
126 Example: heredoc.Doc(`
127 # Create a document from a file
128 $ gh issue artifact create 142 signin-plan.md
129
130 # Create documents from two files, naming the first
131 $ gh issue artifact create 142 'docs/signin-plan.md#Sign-in plan' oauth-research.md
132
133 # Create an HTML document from a file
134 $ gh issue artifact create 142 menu-prototype.html
135
136 # Create a link with a name
137 $ gh issue artifact create 142 https://github.com/monalisa/monas-cafe/wiki/OAuth-runbook --name 'Staging OAuth runbook'
138
139 # Create a document from standard input
140 $ cat order-sync.log | gh issue artifact create 142 --body-file - --name 'Order sync log'
141
142 # Upload an image that the document references
143 $ gh issue artifact create 142 signin-plan.md --attach ./signin-flow.png
144 `),
145 Aliases: []string{"new"},
146 Args: cobra.MinimumNArgs(1),
147 RunE: func(cmd *cobra.Command, args []string) error {
148 var err error
149 opts.IssueNumber, opts.BaseRepo, err = shared.ParseIssueArg(args[0], f.BaseRepo)
150 if err != nil {
151 return cmdutil.FlagErrorWrap(err)
152 }
153
154 // An empty --body-file names no file, as in gh issue create.
155 bodySet := cmd.Flags().Changed("body")
156 bodyFileSet := bodyFile != ""

Callers 1

TestNewCmdCreateFunction · 0.70

Calls 15

ParseIssueArgFunction · 0.92
FlagErrorWrapFunction · 0.92
MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
SupportsAttachmentsFunction · 0.92
BeginTelemetryFunction · 0.92
ClientFuncFunction · 0.92
StringEnumFlagFunction · 0.92
AddFlagFunction · 0.92
parseSourceFunction · 0.85
ChangedMethod · 0.80
artifactTypeMethod · 0.80

Tested by 1

TestNewCmdCreateFunction · 0.56