Skip to content

Commit fb9439c

Browse files
committed
Refactor format semantics
1 parent 0f25466 commit fb9439c

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

cmd/namigo/sub/search_priv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// displayResults prints results.
12-
func displayResults(results any, formatter search.ResultFormatter, format model.OutputFormat) {
12+
func displayResults(results any, formatter search.ResultFormatter, format model.FormatOption) {
1313
switch res := results.(type) {
1414
case []model.GoPackage:
1515
if len(res) > 0 {
@@ -35,9 +35,9 @@ func displayResults(results any, formatter search.ResultFormatter, format model.
3535
}
3636

3737
// displayResultsHelper prints results by data type and output mode.
38-
func displayResultsHelper[T any](results []T, formatter search.ResultFormatter, format model.OutputFormat) {
38+
func displayResultsHelper[T any](results []T, formatter search.ResultFormatter, format model.FormatOption) {
3939
switch format {
40-
case model.JSONFormat:
40+
case model.JSONOption:
4141
type wrapper struct {
4242
Label string `json:"label"`
4343
Results []T `json:"results"`
@@ -49,7 +49,7 @@ func displayResultsHelper[T any](results []T, formatter search.ResultFormatter,
4949
return
5050
}
5151
fmt.Printf("%s\n", data)
52-
case model.TextFormat:
52+
case model.TextOption:
5353
for _, r := range results {
5454
fmt.Println(formatter.Format(r))
5555
}

internal/model/format.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
package model
22

3-
// OutputFormat represents the output mode.
4-
type OutputFormat int
3+
// FormatOption represents the output mode.
4+
type FormatOption int
55

66
const (
7-
TextFormat OutputFormat = iota
8-
JSONFormat
7+
TextOption FormatOption = iota
8+
JSONOption
99

1010
TextValue = "text"
1111
JSONValue = "json"
1212
)
1313

1414
// GetOutputFormat returns an OutputMode instance.
15-
func GetOutputFormat(format string) OutputFormat {
15+
func GetOutputFormat(format string) FormatOption {
1616
switch format {
1717
case TextValue:
18-
return TextFormat
18+
return TextOption
1919
case JSONValue:
20-
return JSONFormat
20+
return JSONOption
2121
default:
22-
return TextFormat
22+
return TextOption
2323
}
2424
}
2525

2626
// String returns the string representation of the output mode.
27-
func (o OutputFormat) String() string {
27+
func (o FormatOption) String() string {
2828
switch o {
29-
case TextFormat:
29+
case TextOption:
3030
return "PlainText"
31-
case JSONFormat:
31+
case JSONOption:
3232
return "JSON"
3333
default:
3434
return "Unknown"

internal/model/format_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ func TestGetOutputFormat(t *testing.T) {
1010
tests := []struct {
1111
name string
1212
format string
13-
expected model.OutputFormat
13+
expected model.FormatOption
1414
}{
15-
{"Text format", "text", model.TextFormat},
16-
{"JSON format", "json", model.JSONFormat},
17-
{"Default format", "unknown", model.TextFormat},
15+
{"Text format", "text", model.TextOption},
16+
{"JSON format", "json", model.JSONOption},
17+
{"Default format", "unknown", model.TextOption},
1818
}
1919

2020
for _, tt := range tests {

0 commit comments

Comments
 (0)