MCPcopy Create free account
hub / github.com/Scalingo/cli / Run

Function Run

apps/run.go:57–256  ·  view source on GitHub ↗
(ctx context.Context, opts RunOpts)

Source from the content-addressed store, hash-verified

55}
56
57func 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 }

Callers 6

runOneOffCommandFunction · 0.92
PgSQLConsoleFunction · 0.92
RedisConsoleFunction · 0.92
InfluxDBConsoleFunction · 0.92
MongoConsoleFunction · 0.92
MySQLConsoleFunction · 0.92

Calls 15

buildEnvMethod · 0.95
validateFilesMethod · 0.95
uploadFilesMethod · 0.95
StartMethod · 0.95
connectToRunServerMethod · 0.95
StopMethod · 0.95
exitCodeMethod · 0.95
ScalingoClientFunction · 0.92
CopyWithFirstReadChanFunction · 0.92
BoldFunction · 0.92
NewSpinnerFunction · 0.92
IsATTYFunction · 0.92

Tested by

no test coverage detected