Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/grounds/commands/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ func NewPushCommand() *cobra.Command {
func newPush() *cobra.Command {
var target string
cmd := &cobra.Command{
Use: "push [--target=dev]",
Use: "push [--target=dev|staging]",
Short: "Build via Gradle plugin and deploy to a target",
Long: `Build the current project with the grounds-push Gradle plugin and deploy it.

Targets:
dev — long-lived, lands in your personal namespace (user-<handle>).
staging — ephemeral preview env, fresh namespace per push, auto-deleted after 7 days.
Public URL pattern: <name>-pr<id>.dev.grnds.io.`,
RunE: func(cmd *cobra.Command, _ []string) error {
if target != "dev" && target != "staging" {
return fmt.Errorf("invalid --target %q: must be \"dev\" or \"staging\"", target)
}
cwd, err := os.Getwd()
if err != nil {
return err
Expand All @@ -38,7 +47,7 @@ func newPush() *cobra.Command {
return gradle.Run(ctx, wrapper, args, cmd.OutOrStdout(), cmd.ErrOrStderr(), 0)
},
}
cmd.Flags().StringVar(&target, "target", "dev", "deploy target: dev")
cmd.Flags().StringVar(&target, "target", "dev", "deploy target: dev (persistent personal ns) or staging (ephemeral preview env, 7d TTL)")
return cmd
}

Expand Down
43 changes: 43 additions & 0 deletions cmd/grounds/commands/push/push_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package push

import (
"bytes"
"strings"
"testing"
)

// Validates the --target flag's allow-list before grounds-push gets
// invoked. The Gradle plugin already rejects bogus targets but
// surfacing the error here gives a faster fail-loud signal and a
// cleaner CLI error.
func TestPushRejectsInvalidTarget(t *testing.T) {
cmd := newPush()
cmd.SetArgs([]string{"--target=production"})
var stderr bytes.Buffer
cmd.SetErr(&stderr)
cmd.SetOut(&stderr)
cmd.SilenceUsage = true

err := cmd.Execute()
if err == nil {
t.Fatal("expected an error for invalid target, got nil")
}
if !strings.Contains(err.Error(), "invalid --target") {
t.Errorf("expected 'invalid --target' in error, got: %v", err)
}
if !strings.Contains(err.Error(), "dev") || !strings.Contains(err.Error(), "staging") {
t.Errorf("expected error to mention 'dev' and 'staging', got: %v", err)
}
}

// Default value should match the help text + Gradle plugin default.
func TestPushDefaultTargetIsDev(t *testing.T) {
cmd := newPush()
flag := cmd.Flag("target")
if flag == nil {
t.Fatal("expected --target flag to exist")
}
if flag.DefValue != "dev" {
t.Errorf("expected default --target=dev, got %q", flag.DefValue)
}
}
Loading