| 193 | } |
| 194 | |
| 195 | func (h *shellCallHandler) Initialize(ctx context.Context) error { |
| 196 | r, err := interp.New( |
| 197 | interp.Params("-e", "-u", "-o", "pipefail"), |
| 198 | interp.CallHandler(h.Call), |
| 199 | interp.ExecHandlers(h.Exec), |
| 200 | |
| 201 | // The "Interactive" option is useful even when not running dagger shell |
| 202 | // in interactive mode. It expands aliases and maybe more in the future. |
| 203 | interp.Interactive(true), |
| 204 | ) |
| 205 | if err != nil { |
| 206 | return err |
| 207 | } |
| 208 | h.runner = r |
| 209 | |
| 210 | // collect initial env + vars |
| 211 | h.runner.Reset() |
| 212 | |
| 213 | h.state = NewStateStore(h.runner) |
| 214 | |
| 215 | // TODO: use `--workdir` and `--no-workdir` flags |
| 216 | var def *moduleDef |
| 217 | var cfg *configuredModule |
| 218 | |
| 219 | if !h.noModule { |
| 220 | def, cfg, err = h.maybeLoadModule(ctx, h.moduleURL, dagger.ModuleServeOpts{Entrypoint: true}) |
| 221 | if err != nil { |
| 222 | return err |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Could be `--no-mod` or module not found from current dir |
| 227 | if def == nil { |
| 228 | def, err = initializeCore(ctx, h.dag) |
| 229 | if err != nil { |
| 230 | return err |
| 231 | } |
| 232 | h.modDefs.Store("", def) |
| 233 | } |
| 234 | |
| 235 | subpath := h.moduleURL |
| 236 | if cfg != nil { |
| 237 | subpath = cfg.Subpath |
| 238 | } |
| 239 | |
| 240 | wd, err := h.newWorkdir(ctx, def, subpath) |
| 241 | if err != nil { |
| 242 | return fmt.Errorf("initial context: %w", err) |
| 243 | } |
| 244 | |
| 245 | h.initwd = *wd |
| 246 | h.wd = h.initwd |
| 247 | |
| 248 | // not h.Debug() on purpose because it's only set from within an interpreter run |
| 249 | if debugFlag { |
| 250 | slog := slog.SpanLogger(ctx, InstrumentationLibrary) |
| 251 | slog.Debug("initial workdir", |
| 252 | "context", h.initwd.Context, |