Skip to content

Commit

Permalink
Rename system.IO to system.Cmd. Add Path field.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Nov 18, 2024
1 parent 4255881 commit d3270cf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions cmd/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ func run() cli.ActionFunc {
defer wasi.Close(c.Context)

return ww.Env{
IO: system.IO{
Args: c.Args().Slice(),
Cmd: system.Cmd{
Path: c.Args().First(),
Args: c.Args().Tail(),
Env: c.StringSlice("env"),
Stdin: stdin(c),
Stdout: c.App.Writer,
Expand Down
5 changes: 3 additions & 2 deletions cmd/internal/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func Command() *cli.Command {
IPFS: ipfs,
Host: h,
Env: ww.Env{
IO: system.IO{
Args: c.Args().Slice(),
Cmd: system.Cmd{
Path: c.Args().First(),
Args: c.Args().Tail(),
Env: c.StringSlice("env"),
Stdin: stdin(c),
Stdout: c.App.Writer,
Expand Down
1 change: 1 addition & 0 deletions proc/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

type Command struct {
Path string
Args, Env []string
Stdout, Stderr io.Writer
}
Expand Down
3 changes: 2 additions & 1 deletion system/io.go → system/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package system

import "io"

type IO struct {
type Cmd struct {
Path string
Stdin io.Reader
Stdout, Stderr io.Writer
Args, Env []string
Expand Down
15 changes: 8 additions & 7 deletions ww.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ var Proto = protoutils.VersionedID{
}

type Env struct {
IO system.IO
Cmd system.Cmd
Net system.Net
FS system.FS
}

func (env Env) Bind(ctx context.Context, r wazero.Runtime) error {
cm, err := env.LoadAndCompile(ctx, r, env.IO.Args[0]) // FIXME: panic if len(args)=0
cm, err := env.LoadAndCompile(ctx, r, env.Cmd.Path) // FIXME: panic if len(args)=0
if err != nil {
return err
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func (env Env) Bind(ctx context.Context, r wazero.Runtime) error {
return err
}

if b, err := io.ReadAll(env.IO.Stdin); err != nil {
if b, err := io.ReadAll(env.Cmd.Stdin); err != nil {
return err
} else if err := call.SetCallData(b); err != nil {
return err
Expand All @@ -78,10 +78,11 @@ func (env Env) Bind(ctx context.Context, r wazero.Runtime) error {

func (env Env) Instantiate(ctx context.Context, r wazero.Runtime, cm wazero.CompiledModule) (*proc.P, error) {
return proc.Command{
Args: env.IO.Args,
Env: env.IO.Env,
Stdout: env.IO.Stdout,
Stderr: env.IO.Stderr,
Path: env.Cmd.Path,
Args: env.Cmd.Args,
Env: env.Cmd.Env,
Stdout: env.Cmd.Stdout,
Stderr: env.Cmd.Stderr,
}.Instantiate(ctx, r, cm)
}

Expand Down

0 comments on commit d3270cf

Please sign in to comment.