Skip to content

Commit

Permalink
fix: add --watch to ftl schema get (#1824)
Browse files Browse the repository at this point in the history
Fixes #1626
  • Loading branch information
safeer authored Jun 18, 2024
1 parent 634c840 commit c668288
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 5 additions & 6 deletions cmd/ftl/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import (
)

type initCmd struct {
Hermit bool `help:"Include Hermit language-specific toolchain binaries." negatable:""`
Dir string `arg:"" help:"Directory to initialize the project in."`
ExternalDirs []string `help:"Directories of existing external modules."`
ModuleDirs []string `help:"Child directories of existing modules."`
NoGit bool `help:"Don't add files to the git repository."`
Startup string `help:"Command to run on startup."`
Hermit bool `help:"Include Hermit language-specific toolchain binaries." negatable:""`
Dir string `arg:"" help:"Directory to initialize the project in."`
ModuleDirs []string `help:"Child directories of existing modules."`
NoGit bool `help:"Don't add files to the git repository."`
Startup string `help:"Command to run on startup."`
}

func (i initCmd) Run(ctx context.Context) error {
Expand Down
20 changes: 14 additions & 6 deletions cmd/ftl/cmd_schema_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"slices"
"strings"

"connectrpc.com/connect"
"golang.org/x/exp/maps"
Expand All @@ -17,6 +18,7 @@ import (
)

type getSchemaCmd struct {
Watch bool `help:"Watch for changes to the schema."`
Protobuf bool `help:"Output the schema as binary protobuf."`
Modules []string `help:"Modules to include" type:"string" optional:""`
}
Expand Down Expand Up @@ -44,17 +46,23 @@ func (g *getSchemaCmd) Run(ctx context.Context, client ftlv1connect.ControllerSe
delete(remainingNames, msg.Schema.Name)
}
if !msg.More {
break
missingNames := maps.Keys(remainingNames)
slices.Sort(missingNames)
if len(missingNames) > 0 {
if g.Watch {
fmt.Printf("missing modules: %s\n", strings.Join(missingNames, ", "))
} else {
return fmt.Errorf("missing modules: %s", strings.Join(missingNames, ", "))
}
}
if !g.Watch {
break
}
}
}
if err := resp.Err(); err != nil {
return resp.Err()
}
missingNames := maps.Keys(remainingNames)
slices.Sort(missingNames)
if len(missingNames) > 0 {
return fmt.Errorf("missing modules: %v", missingNames)
}
return nil
}

Expand Down

0 comments on commit c668288

Please sign in to comment.