hyprland/module: deduplicate verify-config output and add json format for check

parent 841688ec
...@@ -40,6 +40,13 @@ func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -40,6 +40,13 @@ func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
if config.IsJSON(cmd) {
if result == nil {
result = []HyprConfigError{}
}
return ui.PrintJSON(result)
}
if len(result) == 0 { if len(result) == 0 {
color.Green(locale.T("No errors")) color.Green(locale.T("No errors"))
return nil return nil
...@@ -90,6 +97,14 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -90,6 +97,14 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
if config.IsJSON(cmd) {
jsonErrors := make([]ModuleErrorJSON, len(result))
for i, e := range result {
jsonErrors[i] = ModuleErrorJSON{Line: e.Line, Text: e.Text}
}
return ui.PrintJSON(jsonErrors)
}
if len(result) == 0 { if len(result) == 0 {
color.Green(locale.T("No errors")) color.Green(locale.T("No errors"))
return nil return nil
......
...@@ -41,6 +41,7 @@ func CommandList() *cli.Command { ...@@ -41,6 +41,7 @@ func CommandList() *cli.Command {
{ {
Name: "check", Name: "check",
Usage: locale.T("Check the Hyprland config"), Usage: locale.T("Check the Hyprland config"),
Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandCheckCommand, Action: HyprlandCheckCommand,
}, },
{ {
...@@ -77,6 +78,7 @@ func CommandList() *cli.Command { ...@@ -77,6 +78,7 @@ func CommandList() *cli.Command {
Name: "check", Name: "check",
Usage: locale.T("Check Hyprland module"), Usage: locale.T("Check Hyprland module"),
ArgsUsage: "module", ArgsUsage: "module",
Flags: []cli.Flag{config.FormatFlag},
Action: HyprlandModuleCheckCommand, Action: HyprlandModuleCheckCommand,
ShellComplete: ShellCompleteModule("all"), ShellComplete: ShellCompleteModule("all"),
}, },
......
...@@ -61,9 +61,9 @@ type HyprPlugin struct { ...@@ -61,9 +61,9 @@ type HyprPlugin struct {
} }
type HyprConfigError struct { type HyprConfigError struct {
File string File string `json:"file"`
Line int Line int `json:"line"`
Text string Text string `json:"text"`
} }
func NewHyprlandManager() (*HyprlandManager, error) { func NewHyprlandManager() (*HyprlandManager, error) {
...@@ -1052,7 +1052,17 @@ func (m *HyprlandManager) parseCheckOutput(out []byte) []HyprConfigError { ...@@ -1052,7 +1052,17 @@ func (m *HyprlandManager) parseCheckOutput(out []byte) []HyprConfigError {
}) })
} }
return res // Дедупликация: Hyprland может дублировать ошибки из source-файлов
seen := make(map[string]bool)
deduped := make([]HyprConfigError, 0, len(res))
for _, e := range res {
key := fmt.Sprintf("%s:%d:%s", e.File, e.Line, e.Text)
if !seen[key] {
seen[key] = true
deduped = append(deduped, e)
}
}
return deduped
} }
func (m *HyprlandManager) removeLine(lineNumber int) { func (m *HyprlandManager) removeLine(lineNumber int) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment