feat: Artisan checklist for application commands, hints and coverage gate

- migrate, migrate:rollback and deferred:purge gain --pretend and --force;
  they and queue:clear confirm only in production on an interactive
  terminal, so deploys over SSH proceed as before
- result lines: Applied N migrations, Rolled back <id> of <plugin>,
  Cleared N jobs from <queue>
- --json for migrate:status, key:generate, route:list, admin:token:create,
  admin:token:list, admin:token:scopes and websockets:health; -q keeps the
  key and the token
- hints for an empty DSN, an unreachable database, an invalid app.key, a
  missing uploads bucket and an application binary run below its root
- flare and websockets:health return bonfire.Reported after printing
- long help and examples for every application command, greeter:hello and
  blog:publish; cmd/summer TestCommandsDocumented fails on any gap
This commit is contained in:
Jakub Zych
2026-10-21 13:16:21 +02:00
parent 168d65cd1b
commit 9d06a78f62
29 changed files with 831 additions and 77 deletions

View File

@@ -3,6 +3,8 @@ package bonfire
import (
"errors"
"io"
"os"
"path/filepath"
"strings"
"git.golem15.com/golem15/summercms/modules/sunscreen"
@@ -173,6 +175,63 @@ func RenderError(w io.Writer, name string, err error, g Globals) {
_ = writeStyled(w, g, b.String())
}
// wrongDirectoryExplanation is the hint added when an application binary
// fails outside its application root.
const wrongDirectoryExplanation = "This command runs from the application root."
// wrongDirectory adds a hint to err when an application binary (any root
// name other than summer) failed while the working directory dir ("" means
// os.Getwd) has no config directory and a parent directory holds
// summer.yaml: compass then found no configuration, which is why the command
// failed (D-19). The Try line is "cd <relative path>; bin/<name> <args>".
// Usage errors, Reported errors and summer are left alone; nothing else
// about the failure changes.
func wrongDirectory(name string, err error, args []string, dir string) error {
if err == nil || name == "summer" || errors.Is(err, ErrReported) || isUsage(err) {
return err
}
if dir == "" {
wd, werr := os.Getwd()
if werr != nil {
return err
}
dir = wd
}
if info, serr := os.Stat(filepath.Join(dir, "config")); serr == nil && info.IsDir() {
return err
}
root := ""
for d := filepath.Dir(dir); ; d = filepath.Dir(d) {
if _, serr := os.Stat(filepath.Join(d, "summer.yaml")); serr == nil {
root = d
break
}
if filepath.Dir(d) == d {
break
}
}
if root == "" {
return err
}
rel, rerr := filepath.Rel(dir, root)
if rerr != nil {
return err
}
try := "cd " + shellQuote(rel) + "; {bin}"
for _, a := range args {
try += " " + shellQuote(a)
}
return &HintError{Err: err, Explanation: wrongDirectoryExplanation, Try: try}
}
// shellQuote single-quotes s when a shell would split or expand it.
func shellQuote(s string) string {
if s != "" && !strings.ContainsAny(s, " \t\n'\"\\$`*?[]{}()<>|&;#~!") {
return s
}
return "'" + strings.ReplaceAll(s, "'", `'\''`) + "'"
}
// parseUnknownCommand reads the command name and cobra's "Did you mean
// this?" suggestions from an unknown command error.
func parseUnknownCommand(msg string) (string, []string) {