refactor(php,vm): migrate to cli ANSI styling

Removes direct lipgloss imports.
Migrates cli.Line usage to cli.Blank/Echo.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Snider 2026-01-31 23:01:21 +00:00
parent a134e2c6dc
commit 6f3d8341d5
7 changed files with 38 additions and 40 deletions

View file

@ -2,7 +2,6 @@
package php
import (
"github.com/charmbracelet/lipgloss"
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/i18n"
"github.com/spf13/cobra"
@ -22,17 +21,17 @@ var (
// Service colors for log output (domain-specific, keep local)
var (
phpFrankenPHPStyle = lipgloss.NewStyle().Foreground(cli.ColourIndigo500)
phpViteStyle = lipgloss.NewStyle().Foreground(cli.ColourYellow500)
phpHorizonStyle = lipgloss.NewStyle().Foreground(cli.ColourOrange500)
phpReverbStyle = lipgloss.NewStyle().Foreground(cli.ColourViolet500)
phpRedisStyle = lipgloss.NewStyle().Foreground(cli.ColourRed500)
phpFrankenPHPStyle = cli.NewStyle().Foreground(cli.ColourIndigo500)
phpViteStyle = cli.NewStyle().Foreground(cli.ColourYellow500)
phpHorizonStyle = cli.NewStyle().Foreground(cli.ColourOrange500)
phpReverbStyle = cli.NewStyle().Foreground(cli.ColourViolet500)
phpRedisStyle = cli.NewStyle().Foreground(cli.ColourRed500)
)
// Status styles (from shared)
var (
phpStatusRunning = cli.SuccessStyle
phpStatusStopped = cli.StatusPendingStyle
phpStatusStopped = cli.DimStyle
phpStatusError = cli.ErrorStyle
)
@ -41,15 +40,15 @@ var (
phpQAPassedStyle = cli.SuccessStyle
phpQAFailedStyle = cli.ErrorStyle
phpQAWarningStyle = cli.WarningStyle
phpQAStageStyle = cli.StageStyle
phpQAStageStyle = cli.HeaderStyle
)
// Security severity styles (from shared)
var (
phpSecurityCriticalStyle = cli.SeverityCriticalStyle
phpSecurityHighStyle = cli.SeverityHighStyle
phpSecurityMediumStyle = cli.SeverityMediumStyle
phpSecurityLowStyle = cli.SeverityLowStyle
phpSecurityCriticalStyle = cli.NewStyle().Bold().Foreground(cli.ColourRed500)
phpSecurityHighStyle = cli.NewStyle().Bold().Foreground(cli.ColourOrange500)
phpSecurityMediumStyle = cli.NewStyle().Foreground(cli.ColourAmber500)
phpSecurityLowStyle = cli.NewStyle().Foreground(cli.ColourGray500)
)
// AddPHPCommands adds PHP/Laravel development commands.
@ -91,4 +90,4 @@ func AddPHPCommands(root *cobra.Command) {
// Deployment
addPHPDeployCommands(phpCmd)
}
}

View file

@ -102,7 +102,7 @@ func runPHPBuildDocker(ctx context.Context, projectDir string, opts dockerBuildO
if len(config.PHPExtensions) > 0 {
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.extensions")), strings.Join(config.PHPExtensions, ", "))
}
cli.Line("")
cli.Blank()
// Build options
buildOpts := DockerBuildOptions{
@ -132,7 +132,7 @@ func runPHPBuildDocker(ctx context.Context, projectDir string, opts dockerBuildO
if opts.Platform != "" {
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.platform")), opts.Platform)
}
cli.Line("")
cli.Blank()
if err := BuildDocker(ctx, buildOpts); err != nil {
return cli.Err("%s: %w", i18n.T("i18n.fail.build"), err)
@ -170,7 +170,7 @@ func runPHPBuildLinuxKit(ctx context.Context, projectDir string, opts linuxKitBu
cli.Print("%s %s\n", dimStyle.Render(i18n.Label("template")), buildOpts.Template)
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.format")), buildOpts.Format)
cli.Line("")
cli.Blank()
if err := BuildLinuxKit(ctx, buildOpts); err != nil {
return cli.Err("%s: %w", i18n.T("i18n.fail.build"), err)
@ -243,7 +243,7 @@ func addPHPServeCommand(parent *cobra.Command) {
cli.Print("%s http://localhost:%d, https://localhost:%d\n",
dimStyle.Render("Ports:"), effectivePort, effectiveHTTPSPort)
cli.Line("")
cli.Blank()
if err := ServeProduction(ctx, opts); err != nil {
return cli.Err("%s: %w", i18n.T("i18n.fail.start", "container"), err)

View file

@ -12,9 +12,9 @@ import (
// Deploy command styles (aliases to shared)
var (
phpDeployStyle = cli.DeploySuccessStyle
phpDeployPendingStyle = cli.StatusWarningStyle
phpDeployFailedStyle = cli.StatusErrorStyle
phpDeployStyle = cli.SuccessStyle
phpDeployPendingStyle = cli.WarningStyle
phpDeployFailedStyle = cli.ErrorStyle
)
func addPHPDeployCommands(parent *cobra.Command) {
@ -357,5 +357,5 @@ func printDeploymentSummary(index int, status *DeploymentStatus) {
cli.Print(" %s", dimStyle.Render(cli.Sprintf("(%s)", age)))
}
cli.Line("")
cli.Blank()
}

View file

@ -10,7 +10,7 @@ import (
"syscall"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/i18n"
"github.com/spf13/cobra"
@ -90,7 +90,7 @@ func runPHPDev(opts phpDevOptions) error {
for _, svc := range services {
cli.Print(" %s %s\n", successStyle.Render("*"), svc)
}
cli.Line("")
cli.Blank()
// Setup options
port := opts.Port
@ -132,7 +132,7 @@ func runPHPDev(opts phpDevOptions) error {
// Print status
cli.Print("%s %s\n", successStyle.Render(i18n.T("cmd.php.label.running")), i18n.T("cmd.php.dev.services_started"))
printServiceStatuses(server.Status())
cli.Line("")
cli.Blank()
// Print URLs
appURL := GetLaravelAppURL(cwd)
@ -313,7 +313,7 @@ func runPHPStatus() error {
style := getServiceStyle(string(svc))
cli.Print(" %s %s\n", style.Render("*"), svc)
}
cli.Line("")
cli.Blank()
// Package manager
pm := DetectPackageManager(cwd)
@ -435,7 +435,7 @@ func printColoredLog(line string) {
// Parse service prefix from log line
timestamp := time.Now().Format("15:04:05")
var style lipgloss.Style
var style *cli.AnsiStyle
serviceName := ""
if strings.HasPrefix(line, "[FrankenPHP]") {
@ -471,7 +471,7 @@ func printColoredLog(line string) {
)
}
func getServiceStyle(name string) lipgloss.Style {
func getServiceStyle(name string) *cli.AnsiStyle {
switch strings.ToLower(name) {
case "frankenphp":
return phpFrankenPHPStyle

View file

@ -135,7 +135,7 @@ func addPHPPackagesListCommand(parent *cobra.Command) {
cli.Print(" %s %s\n", successStyle.Render("*"), name)
cli.Print(" %s %s\n", dimStyle.Render(i18n.Label("path")), pkg.Path)
cli.Print(" %s %s\n", dimStyle.Render(i18n.Label("version")), version)
cli.Line("")
cli.Blank()
}
return nil

View file

@ -6,7 +6,7 @@ import (
"os"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/i18n"
"github.com/spf13/cobra"
@ -333,7 +333,7 @@ func addPHPAuditCommand(parent *cobra.Command) {
}
}
cli.Line("")
cli.Blank()
if totalVulns > 0 {
cli.Print("%s %s\n", errorStyle.Render(i18n.Label("warning")), i18n.T("cmd.php.audit.found_vulns", map[string]interface{}{"Count": totalVulns}))
@ -400,7 +400,7 @@ func addPHPSecurityCommand(parent *cobra.Command) {
category := strings.Split(check.ID, "_")[0]
if category != currentCategory {
if currentCategory != "" {
cli.Line("")
cli.Blank()
}
currentCategory = category
cli.Print(" %s\n", dimStyle.Render(strings.ToUpper(category)+i18n.T("cmd.php.security.checks_suffix")))
@ -420,7 +420,7 @@ func addPHPSecurityCommand(parent *cobra.Command) {
}
}
cli.Line("")
cli.Blank()
// Print summary
cli.Print("%s %s\n", dimStyle.Render(i18n.Label("summary")), i18n.T("cmd.php.security.summary"))
@ -509,7 +509,7 @@ func addPHPQACommand(parent *cobra.Command) {
stage := getCheckStage(checkResult.Name, stages, cwd)
if stage != currentStage {
if currentStage != "" {
cli.Line("")
cli.Blank()
}
currentStage = stage
cli.Print("%s\n", phpQAStageStyle.Render("── "+strings.ToUpper(stage)+" ──"))
@ -527,7 +527,7 @@ func addPHPQACommand(parent *cobra.Command) {
cli.Print(" %s %s %s %s\n", icon, checkResult.Name, status, dimStyle.Render(checkResult.Duration))
}
cli.Line("")
cli.Blank()
// Print summary
if result.Passed {
@ -740,7 +740,7 @@ func addPHPInfectionCommand(parent *cobra.Command) {
parent.AddCommand(infectionCmd)
}
func getSeverityStyle(severity string) lipgloss.Style {
func getSeverityStyle(severity string) *cli.AnsiStyle {
switch strings.ToLower(severity) {
case "critical":
return phpSecurityCriticalStyle

View file

@ -2,7 +2,6 @@
package vm
import (
"github.com/charmbracelet/lipgloss"
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/i18n"
"github.com/spf13/cobra"
@ -14,7 +13,7 @@ func init() {
// Style aliases from shared
var (
repoNameStyle = cli.RepoNameStyle
repoNameStyle = cli.RepoStyle
successStyle = cli.SuccessStyle
errorStyle = cli.ErrorStyle
dimStyle = cli.DimStyle
@ -22,8 +21,8 @@ var (
// VM-specific styles
var (
varStyle = lipgloss.NewStyle().Foreground(cli.ColourAmber500)
defaultStyle = lipgloss.NewStyle().Foreground(cli.ColourGray500).Italic(true)
varStyle = cli.NewStyle().Foreground(cli.ColourAmber500)
defaultStyle = cli.NewStyle().Foreground(cli.ColourGray500).Italic()
)
// AddVMCommands adds container-related commands under 'vm' to the CLI.
@ -41,4 +40,4 @@ func AddVMCommands(root *cobra.Command) {
addVMLogsCommand(vmCmd)
addVMExecCommand(vmCmd)
addVMTemplatesCommand(vmCmd)
}
}