(ctx context.Context, opts RunOpts)
| 55 | } |
| 56 | |
| 57 | func Run(ctx context.Context, opts RunOpts) error { |
| 58 | c, err := config.ScalingoClient(ctx) |
| 59 | if err != nil { |
| 60 | return errors.Wrap(ctx, err, "get Scalingo client") |
| 61 | } |
| 62 | |
| 63 | firstReadDone := make(chan struct{}) |
| 64 | runCtx := &runContext{ |
| 65 | app: opts.App, |
| 66 | waitingTextOutputWriter: os.Stderr, |
| 67 | stdinCopyFunc: stdio.Copy, |
| 68 | stdoutCopyFunc: io.CopyWithFirstReadChan(firstReadDone), |
| 69 | scalingoClient: c, |
| 70 | } |
| 71 | if opts.Type != "" { |
| 72 | processes, err := c.AppsContainerTypes(ctx, opts.App) |
| 73 | if err != nil { |
| 74 | return errors.Wrap(ctx, err, "get container types") |
| 75 | } |
| 76 | for _, p := range processes { |
| 77 | if p.Name == opts.Type { |
| 78 | opts.Cmd = strings.Split(p.Command, " ") |
| 79 | } |
| 80 | } |
| 81 | if strings.Join(opts.Cmd, "") == "" { |
| 82 | return errors.New(ctx, "no such type") |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if opts.Size == "" { |
| 87 | opts.Size = "M" |
| 88 | } |
| 89 | |
| 90 | if opts.CmdEnv == nil { |
| 91 | opts.CmdEnv = []string{} |
| 92 | } |
| 93 | if opts.Files == nil { |
| 94 | opts.Files = []string{} |
| 95 | } |
| 96 | if opts.Silent { |
| 97 | runCtx.waitingTextOutputWriter = new(bytes.Buffer) |
| 98 | } |
| 99 | if opts.StdinCopyFunc != nil { |
| 100 | runCtx.stdinCopyFunc = opts.StdinCopyFunc |
| 101 | } |
| 102 | if opts.StdoutCopyFunc != nil { |
| 103 | runCtx.stdoutCopyFunc = opts.StdoutCopyFunc |
| 104 | } |
| 105 | |
| 106 | env, err := runCtx.buildEnv(ctx, opts.CmdEnv) |
| 107 | if err != nil { |
| 108 | return errors.Wrap(ctx, err, "build environment") |
| 109 | } |
| 110 | |
| 111 | err = runCtx.validateFiles(ctx, opts.Files) |
| 112 | if err != nil { |
| 113 | return errors.Wrap(ctx, err, "validate files") |
| 114 | } |
no test coverage detected