MCPcopy Index your code
hub / github.com/coder/coder / upload

Method upload

cli/templatepush.go:320–355  ·  view source on GitHub ↗
(inv *serpent.Invocation, client *codersdk.Client)

Source from the content-addressed store, hash-verified

318}
319
320func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.Client) (*codersdk.UploadResponse, error) {
321 var content io.Reader
322 if pf.stdin(inv) {
323 content = inv.Stdin
324 } else {
325 prettyDir := prettyDirectoryPath(pf.directory)
326 _, err := cliui.Prompt(inv, cliui.PromptOptions{
327 Text: fmt.Sprintf("Upload %q?", prettyDir),
328 IsConfirm: true,
329 Default: cliui.ConfirmYes,
330 })
331 if err != nil {
332 return nil, err
333 }
334
335 pipeReader, pipeWriter := io.Pipe()
336 go func() {
337 err := provisionersdk.Tar(pipeWriter, inv.Logger, pf.directory, provisionersdk.TemplateArchiveLimit)
338 _ = pipeWriter.CloseWithError(err)
339 }()
340 defer pipeReader.Close()
341 content = pipeReader
342 }
343
344 spin := spinner.New(spinner.CharSets[5], 100*time.Millisecond)
345 spin.Writer = inv.Stdout
346 spin.Suffix = pretty.Sprint(cliui.DefaultStyles.Keyword, " Uploading directory...")
347 spin.Start()
348 defer spin.Stop()
349
350 resp, err := client.Upload(inv.Context(), codersdk.ContentTypeTar, bufio.NewReader(content))
351 if err != nil {
352 return nil, xerrors.Errorf("upload: %w", err)
353 }
354 return &resp, nil
355}
356
357func (pf *templateUploadFlags) checkForLockfile(inv *serpent.Invocation) error {
358 if pf.stdin(inv) || pf.ignoreLockfile {

Callers 2

templateCreateMethod · 0.80
templatePushMethod · 0.80

Calls 11

stdinMethod · 0.95
PromptFunction · 0.92
TarFunction · 0.92
prettyDirectoryPathFunction · 0.85
CloseMethod · 0.65
NewMethod · 0.65
StartMethod · 0.65
StopMethod · 0.65
UploadMethod · 0.65
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected