Skip to content

Commit

Permalink
clientgen: default to local env if no env is specified (#1728)
Browse files Browse the repository at this point in the history
Co-authored-by: André Eriksson <[email protected]>
  • Loading branch information
fredr and eandre authored Jan 23, 2025
1 parent a4a31c5 commit 16534a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cli/cmd/encore/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func init() {
Short: "Generates an API client for your app",
Long: `Generates an API client for your app.
By default generates the API based on your primary production environment.
Use '--env=local' to generate it based on your local development version of the app.
By default generates the API based on your local environment.
Use '--env=<name>' to generate it based on your cloud environments.
Supported language codes are:
typescript: A TypeScript client using the Fetch API
Expand Down Expand Up @@ -175,7 +175,7 @@ which may require the user-facing wrapper code to be manually generated.`,
genClientCmd.Flags().StringVarP(&output, "output", "o", "", "The filename to write the generated client code to")
_ = genClientCmd.MarkFlagFilename("output", "go", "ts", "tsx", "js", "jsx")

genClientCmd.Flags().StringVarP(&envName, "env", "e", "", "The environment to fetch the API for (defaults to the primary environment)")
genClientCmd.Flags().StringVarP(&envName, "env", "e", "local", "The environment to fetch the API for (defaults to the local environment)")
_ = genClientCmd.RegisterFlagCompletionFunc("env", cmdutil.AutoCompleteEnvSlug)

genClientCmd.Flags().StringSliceVarP(&genServiceNames, "services", "s", nil, "The names of the services to include in the output")
Expand Down
12 changes: 7 additions & 5 deletions cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ func New(appsMgr *apps.Manager, mgr *run.Manager, cm *sqldb.ClusterManager, sm *
// GenClient generates a client based on the app's API.
func (s *Server) GenClient(ctx context.Context, params *daemonpb.GenClientRequest) (*daemonpb.GenClientResponse, error) {
var md *meta.Data
if params.EnvName == "local" {

envName := params.EnvName
if envName == "" {
envName = "local"
}

if envName == "local" {
// Determine the app root
app, err := s.apps.FindLatestByPlatformOrLocalID(params.AppId)
if errors.Is(err, apps.ErrNotFound) {
Expand Down Expand Up @@ -120,10 +126,6 @@ func (s *Server) GenClient(ctx context.Context, params *daemonpb.GenClientReques
return nil, status.Errorf(codes.Internal, "failed to cache app metadata: %v", err)
}
} else {
envName := params.EnvName
if envName == "" {
envName = "@primary"
}
meta, err := platform.GetEnvMeta(ctx, params.AppId, envName)
if err != nil {
if strings.Contains(err.Error(), "env_not_found") || strings.Contains(err.Error(), "env_not_deployed") {
Expand Down

0 comments on commit 16534a5

Please sign in to comment.