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
4 changes: 2 additions & 2 deletions internal/commands/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newActivityListCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(events, fmt.Sprintf("%d events", len(events)),
output.Breadcrumb{Action: "stats", Cmd: "dhq activity stats"},
))
Expand Down Expand Up @@ -76,7 +76,7 @@ func newActivityStatsCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(result, "Account activity with stats",
output.Breadcrumb{Action: "events", Cmd: "dhq activity list"},
))
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/assist.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ All data stays on your machine — nothing is sent to external services.`,
messages := assist.BuildMessages(contextStr, question)

// Stream to TTY, or return complete response for JSON/pipe
if env.IsTTY && !env.JSONMode && !noStream {
if env.IsTTY && !env.WantsJSON() && !noStream {
env.Status("")
fmt.Fprint(env.Stderr, "✨ ") //nolint:errcheck
return ollama.ChatStream(cliCtx.Background(), messages, env.Stderr)
Expand All @@ -96,7 +96,7 @@ All data stays on your machine — nothing is sent to external services.`,
return err
}

if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(
map[string]string{"answer": response, "model": ollama.Model},
"assist response",
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/auto_deploys.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Use these commands to enable, disable, and list auto-deploy configuration per se
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(result, fmt.Sprintf("Auto deploy URL: %s", result.WebhookURL)))
}
env.Status("Webhook URL: %s", result.WebhookURL)
Expand Down Expand Up @@ -80,7 +80,7 @@ func newAutoDeploysEnableCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
action := "Enabled"
if disable {
action = "Disabled"
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/build_cache_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The cache can be bypassed for a single deploy with "dhq deployments create --use
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(files, fmt.Sprintf("%d build cache files", len(files))))
}
rows := make([][]string, len(files))
Expand Down Expand Up @@ -91,7 +91,7 @@ func newBuildCacheFilesCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(f, fmt.Sprintf("Created: %s", f.Path)))
}
env.Status("Created build cache file: %s", f.Path)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/build_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The output of build commands becomes the artifact that gets deployed. Each comma
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(cmds, fmt.Sprintf("%d build commands", len(cmds)),
output.Breadcrumb{Action: "update", Cmd: "dhq build-commands update <identifier> -p <project> --command <cmd>"},
output.Breadcrumb{Action: "delete", Cmd: "dhq build-commands delete <identifier> -p <project>"},
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/build_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newBuildConfigsCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(configs, fmt.Sprintf("%d build configs", len(configs))))
}
rows := make([][]string, len(configs))
Expand Down Expand Up @@ -131,7 +131,7 @@ func newBuildConfigsCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(config, fmt.Sprintf("Created: %s", config.Identifier)))
}
env.Status("Created build config: %s", config.Identifier)
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/build_known_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newBuildKnownHostsCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(hosts, fmt.Sprintf("%d build known hosts", len(hosts))))
}
rows := make([][]string, len(hosts))
Expand Down Expand Up @@ -88,7 +88,7 @@ func newBuildKnownHostsCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(h, fmt.Sprintf("Created: %s", h.Hostname)))
}
env.Status("Created build known host: %s", h.Hostname)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/build_languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newBuildLanguagesSetCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(lang, lang.Name+" "+lang.Version))
}
env.Status("Set %s to version %s", lang.Name, lang.Version)
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/config_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newConfigFilesListCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(files, fmt.Sprintf("%d config files", len(files))))
}
rows := make([][]string, len(files))
Expand Down Expand Up @@ -73,7 +73,7 @@ func newConfigFilesShowCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(f, f.Path))
}
env.WriteTable([]string{"Field", "Value"}, [][]string{
Expand Down
8 changes: 4 additions & 4 deletions internal/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func newDeployCmd() *cobra.Command {
return err
}

if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(preview,
fmt.Sprintf("Preview %s created (status: %s)", preview.Identifier, preview.Status),
output.Breadcrumb{Action: "execute", Cmd: deployExecuteCmd(projectID, server, branch)},
Expand All @@ -431,7 +431,7 @@ func newDeployCmd() *cobra.Command {
return err
}

if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "watch", Cmd: fmt.Sprintf("dhq deployments watch %s -p %s", dep.Identifier, projectID), Resource: "deployment", ID: dep.Identifier},
Expand Down Expand Up @@ -512,7 +512,7 @@ func newRetryCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Retry deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "status", Cmd: fmt.Sprintf("dhq deployments show %s -p %s", dep.Identifier, projectID)},
Expand Down Expand Up @@ -548,7 +548,7 @@ func newRollbackCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Rollback deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "status", Cmd: fmt.Sprintf("dhq deployments show %s -p %s", dep.Identifier, projectID)},
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/deployment_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Three check types are supported:
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(checks, fmt.Sprintf("%d deployment checks", len(checks))))
}
rows := make([][]string, len(checks))
Expand Down
21 changes: 15 additions & 6 deletions internal/commands/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newDeploymentsListCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewPaginatedResponse(result.Records,
output.Pagination{
CurrentPage: result.Pagination.CurrentPage,
Expand All @@ -77,6 +77,15 @@ func newDeploymentsListCmd() *cobra.Command {
))
}

if env.QuietMode {
identifiers := make([]string, len(result.Records))
for i, d := range result.Records {
identifiers[i] = d.Identifier
}
env.WriteQuiet(identifiers)
return nil
}

columns := []string{"Identifier", "Status", "Branch", "Deployer", "Queued"}
rows := make([][]string, len(result.Records))
for i, d := range result.Records {
Expand Down Expand Up @@ -137,7 +146,7 @@ func newDeploymentsShowCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
crumbs := []output.Breadcrumb{
{Action: "logs", Cmd: fmt.Sprintf("dhq deployments logs %s -p %s", dep.Identifier, projectID)},
}
Expand Down Expand Up @@ -263,7 +272,7 @@ func newDeploymentsCreateCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "status", Cmd: fmt.Sprintf("dhq deployments show %s -p %s", dep.Identifier, projectID)},
Expand Down Expand Up @@ -306,7 +315,7 @@ func newDeploymentsRetryCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Retry deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "status", Cmd: fmt.Sprintf("dhq deployments show %s -p %s", dep.Identifier, projectID)},
Expand Down Expand Up @@ -367,7 +376,7 @@ func newDeploymentsRollbackCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(dep,
fmt.Sprintf("Rollback deployment %s queued", dep.Identifier),
output.Breadcrumb{Action: "status", Cmd: fmt.Sprintf("dhq deployments show %s -p %s", dep.Identifier, projectID)},
Expand Down Expand Up @@ -436,7 +445,7 @@ func newDeploymentsLogsCmd() *cobra.Command {
}

env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(logs, fmt.Sprintf("%d log entries", len(logs))))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/commands/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newDoctorCmd() *cobra.Command {
}

// Output
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(checks, "Health check complete"))
}

Expand Down
8 changes: 4 additions & 4 deletions internal/commands/env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newEnvVarsListCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(vars, fmt.Sprintf("%d environment variables", len(vars))))
}
rows := make([][]string, len(vars))
Expand Down Expand Up @@ -149,7 +149,7 @@ func newEnvVarsCreateCmd() *cobra.Command {
if err != nil {
return err
}
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(v, fmt.Sprintf("Created: %s", v.Name)))
}
env.Status("Created environment variable: %s", v.Name)
Expand Down Expand Up @@ -238,7 +238,7 @@ Project-level variables ("dhq env-vars") with the same name override globals for
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(vars, fmt.Sprintf("%d global env vars", len(vars))))
}
rows := make([][]string, len(vars))
Expand Down Expand Up @@ -319,7 +319,7 @@ func newGlobalEnvVarsCreateCmd() *cobra.Command {
if err != nil {
return err
}
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(v, fmt.Sprintf("Created: %s", v.Name)))
}
env.Status("Created global env var: %s", v.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/excluded_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Patterns are evaluated against repository paths and apply per-project. Each excl
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(files, fmt.Sprintf("%d excluded files", len(files))))
}
rows := make([][]string, len(files))
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/global_config_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newGlobalConfigFilesCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(files, fmt.Sprintf("%d global config files", len(files))))
}
rows := make([][]string, len(files))
Expand All @@ -50,7 +50,7 @@ func newGlobalConfigFilesCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(f, f.Name))
}
env.WriteTable([]string{"Field", "Value"}, [][]string{
Expand Down Expand Up @@ -100,7 +100,7 @@ func newGlobalConfigFilesCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(f, fmt.Sprintf("Created: %s", f.Name)))
}
env.Status("Created global config file: %s (%s)", f.Name, f.Identifier)
Expand Down
8 changes: 4 additions & 4 deletions internal/commands/global_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Useful for shared infrastructure (e.g., a single CDN bucket or a shared Heroku s
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(servers, fmt.Sprintf("%d global servers", len(servers))))
}
rows := make([][]string, len(servers))
Expand Down Expand Up @@ -94,7 +94,7 @@ func newGlobalServersCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(s, fmt.Sprintf("Created: %s", s.Name)))
}
env.Status("Created global server: %s (%s)", s.Name, s.Identifier)
Expand Down Expand Up @@ -180,7 +180,7 @@ func newIntegrationsCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(integrations, fmt.Sprintf("%d integrations", len(integrations))))
}
rows := make([][]string, len(integrations))
Expand Down Expand Up @@ -256,7 +256,7 @@ func newIntegrationsCreateCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(ig, fmt.Sprintf("Created: %s", ig.Name)))
}
env.Status("Created integration: %s (%s)", ig.Name, ig.Identifier)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newInsightsCmd() *cobra.Command {

func renderInsights(insights map[string]interface{}, projectID string) error {
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(insights,
fmt.Sprintf("Insights for project: %s", projectID),
))
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/language_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newLanguageVersionsCmd() *cobra.Command {
return err
}
env := cliCtx.Envelope
if env.JSONMode || !env.IsTTY {
if env.WantsJSON() {
return env.WriteJSON(output.NewResponse(versions, fmt.Sprintf("%d languages available", len(versions))))
}

Expand Down
Loading
Loading