-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cli): prettify status output with table, links, and --json flag #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f9e242
feat(cli): prettify status output with table, links, and --json flag
Aureliolo 17ebe96
fix(cli): address 9 review findings from go-reviewer
Aureliolo 5f7fc8a
fix: web healthcheck localhost, doctor health parsing, uptime format
Aureliolo b56bc06
fix: address 8 review findings from go-reviewer, Gemini, CodeRabbit
Aureliolo 840f994
fix: flaky DepartmentFactory test + move logs to top of doctor report
Aureliolo 2823797
feat(cli): styled doctor output, doctor report subcommand
Aureliolo 7d00062
fix(cli): address 6 review findings from external reviewers
Aureliolo 9c94489
fix(cli): address 4 external review findings
Aureliolo b84803d
fix(cli): exact image status match, negative uptime test
Aureliolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
| "os" | ||
| "path/filepath" | ||
| "time" | ||
|
|
||
| "github.com/Aureliolo/synthorg/cli/internal/config" | ||
| "github.com/Aureliolo/synthorg/cli/internal/diagnostics" | ||
| "github.com/Aureliolo/synthorg/cli/internal/ui" | ||
| "github.com/Aureliolo/synthorg/cli/internal/version" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var doctorReportCmd = &cobra.Command{ | ||
| Use: "report", | ||
| Short: "Generate a diagnostic archive and open a bug report", | ||
| Long: "Collects diagnostics, saves a report file, and opens a pre-filled GitHub issue URL in the browser.", | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| RunE: runDoctorReport, | ||
| } | ||
|
|
||
| func init() { | ||
| doctorCmd.AddCommand(doctorReportCmd) | ||
| } | ||
|
|
||
| func runDoctorReport(cmd *cobra.Command, _ []string) error { | ||
| ctx := cmd.Context() | ||
| dir := resolveDataDir() | ||
| out := ui.NewUI(cmd.OutOrStdout()) | ||
|
|
||
| state, err := config.Load(dir) | ||
| if err != nil { | ||
| return fmt.Errorf("loading config: %w", err) | ||
| } | ||
|
|
||
| out.Step("Collecting diagnostics...") | ||
| report := diagnostics.Collect(ctx, state) | ||
|
|
||
| safeDir, err := safeStateDir(state) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Save diagnostic report. | ||
| filename := fmt.Sprintf("synthorg-diagnostic-%s.txt", | ||
| time.Now().Format("20060102-150405")) | ||
| savePath := filepath.Join(safeDir, filename) | ||
| text := report.FormatText() | ||
| if err := os.WriteFile(savePath, []byte(text), 0o600); err != nil { | ||
|
|
||
| return fmt.Errorf("saving diagnostic file: %w", err) | ||
| } | ||
| out.Success(fmt.Sprintf("Diagnostic file: %s", savePath)) | ||
|
|
||
| // Build issue URL. | ||
| issueURL := buildBugReportURL(report, state) | ||
|
|
||
| _, _ = fmt.Fprintln(out.Writer()) | ||
| out.Section("Bug Report") | ||
| out.Hint("1. Open the URL below in your browser") | ||
| out.Hint("2. Attach the diagnostic file to the issue") | ||
| _, _ = fmt.Fprintln(out.Writer()) | ||
| _, _ = fmt.Fprintln(out.Writer(), issueURL) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func buildBugReportURL(report diagnostics.Report, state config.State) string { | ||
| title := fmt.Sprintf("[CLI] Bug report — %s/%s, CLI %s", | ||
| report.OS, report.Arch, report.CLIVersion) | ||
|
|
||
| // Build container summary lines. | ||
| var containers string | ||
| for _, c := range report.ContainerSummary { | ||
| health := c.Health | ||
| if health == "" { | ||
| health = c.State | ||
| } | ||
| containers += fmt.Sprintf("| %s | %s | %s |\n", c.Name, c.State, health) | ||
| } | ||
|
|
||
| body := fmt.Sprintf( | ||
| "## Environment\n\n"+ | ||
| "| Field | Value |\n"+ | ||
| "|-------|-------|\n"+ | ||
| "| OS | %s/%s |\n"+ | ||
| "| CLI | %s (%s) |\n"+ | ||
| "| Docker | %s |\n"+ | ||
| "| Compose | %s |\n"+ | ||
| "| Health | %s |\n"+ | ||
| "| Persistence | %s |\n"+ | ||
| "| Memory | %s |\n"+ | ||
| "| Image tag | %s |\n"+ | ||
| "| Sandbox | %v |\n\n", | ||
| report.OS, report.Arch, | ||
| report.CLIVersion, report.CLICommit, | ||
| report.DockerVersion, report.ComposeVersion, | ||
| report.HealthStatus, | ||
| state.PersistenceBackend, state.MemoryBackend, | ||
| state.ImageTag, state.Sandbox, | ||
| ) | ||
|
|
||
| if containers != "" { | ||
| body += "## Containers\n\n" + | ||
| "| Name | State | Health |\n" + | ||
| "|------|-------|--------|\n" + | ||
| containers + "\n" | ||
| } | ||
|
|
||
| body += "> Attach the diagnostic file from `synthorg doctor report`\n\n" + | ||
| "## Steps to Reproduce\n\n1. \n\n" + | ||
| "## Expected Behavior\n\n\n\n" + | ||
| "## Actual Behavior\n\n" | ||
|
|
||
| // Truncate body if URL would exceed browser limits (~8000 chars). | ||
| encodedBody := url.QueryEscape(body) | ||
| if len(encodedBody) > 6000 { | ||
| body = fmt.Sprintf( | ||
| "## Environment\n\nOS: %s/%s\nCLI: %s\nDocker: %s\nHealth: %s\n\n"+ | ||
| "> Attach the diagnostic file from `synthorg doctor report`\n", | ||
| report.OS, report.Arch, report.CLIVersion, | ||
| report.DockerVersion, report.HealthStatus, | ||
| ) | ||
| encodedBody = url.QueryEscape(body) | ||
| } | ||
|
|
||
| return fmt.Sprintf("%s/issues/new?title=%s&labels=type%%3Abug&body=%s", | ||
| version.RepoURL, | ||
| url.QueryEscape(title), | ||
| encodedBody, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.