diff --git a/internal/macapp/macapp.go b/internal/macapp/macapp.go index 3d394a3..8164fef 100644 --- a/internal/macapp/macapp.go +++ b/internal/macapp/macapp.go @@ -39,7 +39,7 @@ type Application struct { // Website shows the app's website, empty if unknown Website string // ArmSupport shows the Apple Silicon support based on Does It Arm reports - ArmSupport string + ArmSupport remotecheck.Support } // GetAllApplications returns all applications diff --git a/internal/output/output.go b/internal/output/output.go index de8aaa3..16e0e4b 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -13,7 +13,7 @@ func Table(apps []macapp.Application) { table.SetHeader([]string{"Name", "Current ßArchitectures", "Arm Support"}) for _, app := range apps { - table.Append([]string{app.Name, app.Architectures.String(), app.ArmSupport}) + table.Append([]string{app.Name, app.Architectures.String(), app.ArmSupport.String()}) } table.Render() diff --git a/internal/remotecheck/remote.go b/internal/remotecheck/remote.go index 9e5a7ff..22249aa 100644 --- a/internal/remotecheck/remote.go +++ b/internal/remotecheck/remote.go @@ -18,7 +18,7 @@ var ( type AppInfo struct { Website string - ArmSupport string + ArmSupport Support } // Init loads the list of reported app Arm from Does it ARM. @@ -39,9 +39,9 @@ func Init() error { for _, match := range matches { name := match[1] info := AppInfo{ - Website: match[2], - ArmSupport: match[3], + Website: match[2], } + info.ArmSupport.Parse(match[3]) infoCache[name] = info } diff --git a/internal/remotecheck/remote_test.go b/internal/remotecheck/remote_test.go index d9d4905..8bde590 100644 --- a/internal/remotecheck/remote_test.go +++ b/internal/remotecheck/remote_test.go @@ -17,5 +17,5 @@ func TestGetInfo(t *testing.T) { info, err := GetInfo("Go (golang)") assert.Nil(t, err) - assert.Equal(t, "✅", info.ArmSupport) + assert.Equal(t, SupportNative, info.ArmSupport) } diff --git a/internal/remotecheck/support.go b/internal/remotecheck/support.go new file mode 100644 index 0000000..2f3bf0c --- /dev/null +++ b/internal/remotecheck/support.go @@ -0,0 +1,57 @@ +package remotecheck + +type Support uint + +const ( + SupportUndefined Support = iota // zero value + SupportNative + SupportTransition + SupportInDevelopment + SupportNotYet + SupportUnknown +) + +func (s *Support) Parse(str string) Support { + switch str { + case "✅": + *s = SupportNative + + case "✳️": + *s = SupportTransition + + case "⏹": + *s = SupportInDevelopment + + case "🚫": + *s = SupportNotYet + + case "🔶": + *s = SupportUnknown + + } + + return *s +} + +func (s Support) String() string { + switch s { + case SupportNative: + return "Supported" + + case SupportTransition: + return "Supported *" + + case SupportInDevelopment: + return "Unsupported" + + case SupportNotYet: + return "Unsupported" + + case SupportUnknown: + return "Unknown" + + default: + return "" + + } +} diff --git a/internal/remotecheck/support_test.go b/internal/remotecheck/support_test.go new file mode 100644 index 0000000..49d7c2d --- /dev/null +++ b/internal/remotecheck/support_test.go @@ -0,0 +1,29 @@ +package remotecheck + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSupport_Parse(t *testing.T) { + tests := []struct { + in string + expected Support + }{ + {"✅", SupportNative}, + {"✳️", SupportTransition}, + {"⏹", SupportInDevelopment}, + {"🚫", SupportNotYet}, + {"🔶", SupportUnknown}, + {"some other", SupportUndefined}, + } + + for _, test := range tests { + var support Support + actual := support.Parse(test.in) + + assert.Equal(t, test.expected, support) + assert.Equal(t, test.expected, actual) + } +}