Skip to content

Commit

Permalink
support bumping multiple bass.lock files
Browse files Browse the repository at this point in the history
usage: bass --bump a/bass.lock b/bass.lock c/bass.lock

--bump is now a bool flag instead of a string flag. args are used
instead.
  • Loading branch information
vito committed Aug 8, 2022
1 parent 22ad021 commit 2f8cdda
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
92 changes: 51 additions & 41 deletions cmd/bass/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,79 @@ import (

func bump(ctx context.Context) error {
return cli.Task(ctx, cmdline, func(ctx context.Context, vertex *progrock.VertexRecorder) error {
lockContent, err := os.ReadFile(bumpLock)
for _, bumpLock := range flags.Args() {
if err := bumpLockfile(ctx, bumpLock); err != nil {
return err
}
}

return nil
})
}

func bumpLockfile(ctx context.Context, bumpLock string) error {
lockContent, err := os.ReadFile(bumpLock)
if err != nil {
return err
}

content := &proto.Memosphere{}
err = prototext.Unmarshal(lockContent, content)
if err != nil {
return err
}

for _, memo := range content.Memos {
thunk := bass.Thunk{}
err := thunk.UnmarshalProto(memo.Module)
if err != nil {
return err
}

content := &proto.Memosphere{}
err = prototext.Unmarshal(lockContent, content)
scope, err := bass.Bass.Load(ctx, thunk)
if err != nil {
return err
}

for _, memo := range content.Memos {
thunk := bass.Thunk{}
err := thunk.UnmarshalProto(memo.Module)
if err != nil {
return err
}
for _, call := range memo.Calls {
binding := bass.Symbol(call.Binding)

scope, err := bass.Bass.Load(ctx, thunk)
var comb bass.Combiner
err = scope.GetDecode(binding, &comb)
if err != nil {
return err
}

for _, call := range memo.Calls {
binding := bass.Symbol(call.Binding)

var comb bass.Combiner
err = scope.GetDecode(binding, &comb)
for _, res := range call.Results {
input, err := bass.FromProto(res.Input)
if err != nil {
return err
}

for _, res := range call.Results {
input, err := bass.FromProto(res.Input)
if err != nil {
return err
}

out, err := bass.Trampoline(ctx, comb.Call(ctx, input, bass.NewEmptyScope(), bass.Identity))
if err != nil {
return err
}

output, err := bass.MarshalProto(out)
if err != nil {
return err
}
out, err := bass.Trampoline(ctx, comb.Call(ctx, input, bass.NewEmptyScope(), bass.Identity))
if err != nil {
return err
}

res.Output = output
output, err := bass.MarshalProto(out)
if err != nil {
return err
}

res.Output = output
}
}
}

payload, err := prototext.MarshalOptions{Multiline: true}.Marshal(content)
if err != nil {
return err
}
payload, err := prototext.MarshalOptions{Multiline: true}.Marshal(content)
if err != nil {
return err
}

fmted, err := parser.Format(payload)
if err != nil {
return err
}
fmted, err := parser.Format(payload)
if err != nil {
return err
}

return os.WriteFile(bumpLock, fmted, 0644)
})
return os.WriteFile(bumpLock, fmted, 0644)
}
6 changes: 3 additions & 3 deletions cmd/bass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var inputs []string

var runRun bool
var runExport bool
var bumpLock string
var runBump bool
var runPrune bool
var runnerAddr string

Expand All @@ -49,7 +49,7 @@ func init() {

flags.BoolVarP(&runExport, "export", "e", false, "write a thunk path to stdout as a tar stream, or log the tar contents if stdout is a tty")
flags.BoolVar(&runRun, "run", false, "run a thunk read from stdin in JSON format")
flags.StringVarP(&bumpLock, "bump", "b", "", "re-generate all values in a bass.lock file")
flags.BoolVarP(&runBump, "bump", "b", false, "re-generate all calls in bass.lock files")

flags.BoolVarP(&runPrune, "prune", "p", false, "release data and caches retained by runtimes")

Expand Down Expand Up @@ -181,7 +181,7 @@ func root(ctx context.Context) error {
return langServer(ctx)
}

if bumpLock != "" {
if runBump {
return cli.WithProgress(ctx, bump)
}

Expand Down

0 comments on commit 2f8cdda

Please sign in to comment.