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:
parent
a134e2c6dc
commit
6f3d8341d5
7 changed files with 38 additions and 40 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
package php
|
package php
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
"github.com/host-uk/core/pkg/cli"
|
"github.com/host-uk/core/pkg/cli"
|
||||||
"github.com/host-uk/core/pkg/i18n"
|
"github.com/host-uk/core/pkg/i18n"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -22,17 +21,17 @@ var (
|
||||||
|
|
||||||
// Service colors for log output (domain-specific, keep local)
|
// Service colors for log output (domain-specific, keep local)
|
||||||
var (
|
var (
|
||||||
phpFrankenPHPStyle = lipgloss.NewStyle().Foreground(cli.ColourIndigo500)
|
phpFrankenPHPStyle = cli.NewStyle().Foreground(cli.ColourIndigo500)
|
||||||
phpViteStyle = lipgloss.NewStyle().Foreground(cli.ColourYellow500)
|
phpViteStyle = cli.NewStyle().Foreground(cli.ColourYellow500)
|
||||||
phpHorizonStyle = lipgloss.NewStyle().Foreground(cli.ColourOrange500)
|
phpHorizonStyle = cli.NewStyle().Foreground(cli.ColourOrange500)
|
||||||
phpReverbStyle = lipgloss.NewStyle().Foreground(cli.ColourViolet500)
|
phpReverbStyle = cli.NewStyle().Foreground(cli.ColourViolet500)
|
||||||
phpRedisStyle = lipgloss.NewStyle().Foreground(cli.ColourRed500)
|
phpRedisStyle = cli.NewStyle().Foreground(cli.ColourRed500)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status styles (from shared)
|
// Status styles (from shared)
|
||||||
var (
|
var (
|
||||||
phpStatusRunning = cli.SuccessStyle
|
phpStatusRunning = cli.SuccessStyle
|
||||||
phpStatusStopped = cli.StatusPendingStyle
|
phpStatusStopped = cli.DimStyle
|
||||||
phpStatusError = cli.ErrorStyle
|
phpStatusError = cli.ErrorStyle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -41,15 +40,15 @@ var (
|
||||||
phpQAPassedStyle = cli.SuccessStyle
|
phpQAPassedStyle = cli.SuccessStyle
|
||||||
phpQAFailedStyle = cli.ErrorStyle
|
phpQAFailedStyle = cli.ErrorStyle
|
||||||
phpQAWarningStyle = cli.WarningStyle
|
phpQAWarningStyle = cli.WarningStyle
|
||||||
phpQAStageStyle = cli.StageStyle
|
phpQAStageStyle = cli.HeaderStyle
|
||||||
)
|
)
|
||||||
|
|
||||||
// Security severity styles (from shared)
|
// Security severity styles (from shared)
|
||||||
var (
|
var (
|
||||||
phpSecurityCriticalStyle = cli.SeverityCriticalStyle
|
phpSecurityCriticalStyle = cli.NewStyle().Bold().Foreground(cli.ColourRed500)
|
||||||
phpSecurityHighStyle = cli.SeverityHighStyle
|
phpSecurityHighStyle = cli.NewStyle().Bold().Foreground(cli.ColourOrange500)
|
||||||
phpSecurityMediumStyle = cli.SeverityMediumStyle
|
phpSecurityMediumStyle = cli.NewStyle().Foreground(cli.ColourAmber500)
|
||||||
phpSecurityLowStyle = cli.SeverityLowStyle
|
phpSecurityLowStyle = cli.NewStyle().Foreground(cli.ColourGray500)
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddPHPCommands adds PHP/Laravel development commands.
|
// AddPHPCommands adds PHP/Laravel development commands.
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ func runPHPBuildDocker(ctx context.Context, projectDir string, opts dockerBuildO
|
||||||
if len(config.PHPExtensions) > 0 {
|
if len(config.PHPExtensions) > 0 {
|
||||||
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.extensions")), strings.Join(config.PHPExtensions, ", "))
|
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.extensions")), strings.Join(config.PHPExtensions, ", "))
|
||||||
}
|
}
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
// Build options
|
// Build options
|
||||||
buildOpts := DockerBuildOptions{
|
buildOpts := DockerBuildOptions{
|
||||||
|
|
@ -132,7 +132,7 @@ func runPHPBuildDocker(ctx context.Context, projectDir string, opts dockerBuildO
|
||||||
if opts.Platform != "" {
|
if opts.Platform != "" {
|
||||||
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.platform")), 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 {
|
if err := BuildDocker(ctx, buildOpts); err != nil {
|
||||||
return cli.Err("%s: %w", i18n.T("i18n.fail.build"), err)
|
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.Label("template")), buildOpts.Template)
|
||||||
cli.Print("%s %s\n", dimStyle.Render(i18n.T("cmd.php.build.format")), buildOpts.Format)
|
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 {
|
if err := BuildLinuxKit(ctx, buildOpts); err != nil {
|
||||||
return cli.Err("%s: %w", i18n.T("i18n.fail.build"), err)
|
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",
|
cli.Print("%s http://localhost:%d, https://localhost:%d\n",
|
||||||
dimStyle.Render("Ports:"), effectivePort, effectiveHTTPSPort)
|
dimStyle.Render("Ports:"), effectivePort, effectiveHTTPSPort)
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
if err := ServeProduction(ctx, opts); err != nil {
|
if err := ServeProduction(ctx, opts); err != nil {
|
||||||
return cli.Err("%s: %w", i18n.T("i18n.fail.start", "container"), err)
|
return cli.Err("%s: %w", i18n.T("i18n.fail.start", "container"), err)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ import (
|
||||||
|
|
||||||
// Deploy command styles (aliases to shared)
|
// Deploy command styles (aliases to shared)
|
||||||
var (
|
var (
|
||||||
phpDeployStyle = cli.DeploySuccessStyle
|
phpDeployStyle = cli.SuccessStyle
|
||||||
phpDeployPendingStyle = cli.StatusWarningStyle
|
phpDeployPendingStyle = cli.WarningStyle
|
||||||
phpDeployFailedStyle = cli.StatusErrorStyle
|
phpDeployFailedStyle = cli.ErrorStyle
|
||||||
)
|
)
|
||||||
|
|
||||||
func addPHPDeployCommands(parent *cobra.Command) {
|
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.Print(" %s", dimStyle.Render(cli.Sprintf("(%s)", age)))
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
"github.com/host-uk/core/pkg/cli"
|
"github.com/host-uk/core/pkg/cli"
|
||||||
"github.com/host-uk/core/pkg/i18n"
|
"github.com/host-uk/core/pkg/i18n"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -90,7 +90,7 @@ func runPHPDev(opts phpDevOptions) error {
|
||||||
for _, svc := range services {
|
for _, svc := range services {
|
||||||
cli.Print(" %s %s\n", successStyle.Render("*"), svc)
|
cli.Print(" %s %s\n", successStyle.Render("*"), svc)
|
||||||
}
|
}
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
// Setup options
|
// Setup options
|
||||||
port := opts.Port
|
port := opts.Port
|
||||||
|
|
@ -132,7 +132,7 @@ func runPHPDev(opts phpDevOptions) error {
|
||||||
// Print status
|
// Print status
|
||||||
cli.Print("%s %s\n", successStyle.Render(i18n.T("cmd.php.label.running")), i18n.T("cmd.php.dev.services_started"))
|
cli.Print("%s %s\n", successStyle.Render(i18n.T("cmd.php.label.running")), i18n.T("cmd.php.dev.services_started"))
|
||||||
printServiceStatuses(server.Status())
|
printServiceStatuses(server.Status())
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
// Print URLs
|
// Print URLs
|
||||||
appURL := GetLaravelAppURL(cwd)
|
appURL := GetLaravelAppURL(cwd)
|
||||||
|
|
@ -313,7 +313,7 @@ func runPHPStatus() error {
|
||||||
style := getServiceStyle(string(svc))
|
style := getServiceStyle(string(svc))
|
||||||
cli.Print(" %s %s\n", style.Render("*"), svc)
|
cli.Print(" %s %s\n", style.Render("*"), svc)
|
||||||
}
|
}
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
// Package manager
|
// Package manager
|
||||||
pm := DetectPackageManager(cwd)
|
pm := DetectPackageManager(cwd)
|
||||||
|
|
@ -435,7 +435,7 @@ func printColoredLog(line string) {
|
||||||
// Parse service prefix from log line
|
// Parse service prefix from log line
|
||||||
timestamp := time.Now().Format("15:04:05")
|
timestamp := time.Now().Format("15:04:05")
|
||||||
|
|
||||||
var style lipgloss.Style
|
var style *cli.AnsiStyle
|
||||||
serviceName := ""
|
serviceName := ""
|
||||||
|
|
||||||
if strings.HasPrefix(line, "[FrankenPHP]") {
|
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) {
|
switch strings.ToLower(name) {
|
||||||
case "frankenphp":
|
case "frankenphp":
|
||||||
return phpFrankenPHPStyle
|
return phpFrankenPHPStyle
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func addPHPPackagesListCommand(parent *cobra.Command) {
|
||||||
cli.Print(" %s %s\n", successStyle.Render("*"), name)
|
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("path")), pkg.Path)
|
||||||
cli.Print(" %s %s\n", dimStyle.Render(i18n.Label("version")), version)
|
cli.Print(" %s %s\n", dimStyle.Render(i18n.Label("version")), version)
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
"github.com/host-uk/core/pkg/cli"
|
"github.com/host-uk/core/pkg/cli"
|
||||||
"github.com/host-uk/core/pkg/i18n"
|
"github.com/host-uk/core/pkg/i18n"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -333,7 +333,7 @@ func addPHPAuditCommand(parent *cobra.Command) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
if totalVulns > 0 {
|
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}))
|
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]
|
category := strings.Split(check.ID, "_")[0]
|
||||||
if category != currentCategory {
|
if category != currentCategory {
|
||||||
if currentCategory != "" {
|
if currentCategory != "" {
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
}
|
}
|
||||||
currentCategory = category
|
currentCategory = category
|
||||||
cli.Print(" %s\n", dimStyle.Render(strings.ToUpper(category)+i18n.T("cmd.php.security.checks_suffix")))
|
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
|
// Print summary
|
||||||
cli.Print("%s %s\n", dimStyle.Render(i18n.Label("summary")), i18n.T("cmd.php.security.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)
|
stage := getCheckStage(checkResult.Name, stages, cwd)
|
||||||
if stage != currentStage {
|
if stage != currentStage {
|
||||||
if currentStage != "" {
|
if currentStage != "" {
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
}
|
}
|
||||||
currentStage = stage
|
currentStage = stage
|
||||||
cli.Print("%s\n", phpQAStageStyle.Render("── "+strings.ToUpper(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.Print(" %s %s %s %s\n", icon, checkResult.Name, status, dimStyle.Render(checkResult.Duration))
|
||||||
}
|
}
|
||||||
cli.Line("")
|
cli.Blank()
|
||||||
|
|
||||||
// Print summary
|
// Print summary
|
||||||
if result.Passed {
|
if result.Passed {
|
||||||
|
|
@ -740,7 +740,7 @@ func addPHPInfectionCommand(parent *cobra.Command) {
|
||||||
parent.AddCommand(infectionCmd)
|
parent.AddCommand(infectionCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSeverityStyle(severity string) lipgloss.Style {
|
func getSeverityStyle(severity string) *cli.AnsiStyle {
|
||||||
switch strings.ToLower(severity) {
|
switch strings.ToLower(severity) {
|
||||||
case "critical":
|
case "critical":
|
||||||
return phpSecurityCriticalStyle
|
return phpSecurityCriticalStyle
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
"github.com/host-uk/core/pkg/cli"
|
"github.com/host-uk/core/pkg/cli"
|
||||||
"github.com/host-uk/core/pkg/i18n"
|
"github.com/host-uk/core/pkg/i18n"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -14,7 +13,7 @@ func init() {
|
||||||
|
|
||||||
// Style aliases from shared
|
// Style aliases from shared
|
||||||
var (
|
var (
|
||||||
repoNameStyle = cli.RepoNameStyle
|
repoNameStyle = cli.RepoStyle
|
||||||
successStyle = cli.SuccessStyle
|
successStyle = cli.SuccessStyle
|
||||||
errorStyle = cli.ErrorStyle
|
errorStyle = cli.ErrorStyle
|
||||||
dimStyle = cli.DimStyle
|
dimStyle = cli.DimStyle
|
||||||
|
|
@ -22,8 +21,8 @@ var (
|
||||||
|
|
||||||
// VM-specific styles
|
// VM-specific styles
|
||||||
var (
|
var (
|
||||||
varStyle = lipgloss.NewStyle().Foreground(cli.ColourAmber500)
|
varStyle = cli.NewStyle().Foreground(cli.ColourAmber500)
|
||||||
defaultStyle = lipgloss.NewStyle().Foreground(cli.ColourGray500).Italic(true)
|
defaultStyle = cli.NewStyle().Foreground(cli.ColourGray500).Italic()
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddVMCommands adds container-related commands under 'vm' to the CLI.
|
// AddVMCommands adds container-related commands under 'vm' to the CLI.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue