Skip to content

Commit 32faf4b

Browse files
committed
Extract IsURL to utils
1 parent dd32f8a commit 32faf4b

5 files changed

Lines changed: 16 additions & 17 deletions

File tree

cmd/plugins.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/betterdiscord/cli/internal/betterdiscord"
77
"github.com/betterdiscord/cli/internal/output"
8+
"github.com/betterdiscord/cli/internal/utils"
89
"github.com/spf13/cobra"
910
)
1011

@@ -86,7 +87,7 @@ var pluginsInstallCmd = &cobra.Command{
8687
RunE: func(cmd *cobra.Command, args []string) error {
8788
identifier := args[0]
8889
// Check if not a URL and already installed
89-
if !isURL(identifier) {
90+
if !utils.IsURL(identifier) {
9091
if existing := betterdiscord.FindAddon(betterdiscord.AddonPlugin, identifier); existing != nil {
9192
name := existing.Meta.Name
9293
if name == "" {
@@ -140,7 +141,7 @@ var pluginsUpdateCmd = &cobra.Command{
140141
checkOnly, _ := cmd.Flags().GetBool("check")
141142

142143
// For non-URL identifiers, check if update is available
143-
if !isURL(identifier) {
144+
if !utils.IsURL(identifier) {
144145
existing := betterdiscord.FindAddon(betterdiscord.AddonPlugin, identifier)
145146
if existing == nil {
146147
output.Printf("❌ Plugin '%s' is not installed.\n", identifier)

cmd/root.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55
"io"
6-
"net/url"
76
"os"
87
"strings"
98

@@ -45,12 +44,6 @@ func IsDebugBuild() bool {
4544
return buildVersion == "dev"
4645
}
4746

48-
// isURL checks if a string is a valid URL
49-
func isURL(input string) bool {
50-
parsed, err := url.Parse(input)
51-
return err == nil && parsed.Scheme != "" && parsed.Host != ""
52-
}
53-
5447
var silent bool
5548

5649
func init() {

cmd/themes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/betterdiscord/cli/internal/betterdiscord"
77
"github.com/betterdiscord/cli/internal/output"
8+
"github.com/betterdiscord/cli/internal/utils"
89
"github.com/spf13/cobra"
910
)
1011

@@ -75,7 +76,7 @@ var themesInstallCmd = &cobra.Command{
7576
RunE: func(cmd *cobra.Command, args []string) error {
7677
identifier := args[0]
7778
// Check if not a URL and already installed
78-
if !isURL(identifier) {
79+
if !utils.IsURL(identifier) {
7980
if existing := betterdiscord.FindAddon(betterdiscord.AddonTheme, identifier); existing != nil {
8081
name := existing.Meta.Name
8182
if name == "" {
@@ -129,7 +130,7 @@ var themesUpdateCmd = &cobra.Command{
129130
checkOnly, _ := cmd.Flags().GetBool("check")
130131

131132
// For non-URL identifiers, check if update is available
132-
if !isURL(identifier) {
133+
if !utils.IsURL(identifier) {
133134
existing := betterdiscord.FindAddon(betterdiscord.AddonTheme, identifier)
134135
if existing == nil {
135136
output.Printf("❌ Theme '%s' is not installed.\n", identifier)

internal/betterdiscord/addons.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func InstallAddon(kind AddonKind, identifier string) (*ResolvedAddon, error) {
119119
resolved := &ResolvedAddon{}
120120

121121
// Case 1: Direct URL
122-
if isURL(identifier) {
122+
if utils.IsURL(identifier) {
123123
dest, err := downloadAddon(kind, dir, identifier)
124124
if err != nil {
125125
return nil, err
@@ -261,11 +261,6 @@ func candidateFilenames(kind AddonKind, identifier string) []string {
261261
return out
262262
}
263263

264-
func isURL(input string) bool {
265-
parsed, err := url.Parse(input)
266-
return err == nil && parsed.Scheme != "" && parsed.Host != ""
267-
}
268-
269264
// LogLocalAddonInfo prints detailed information about a locally installed addon.
270265
func LogLocalAddonInfo(entry *AddonEntry) {
271266
name := entry.Meta.Name

internal/utils/strings.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package utils
2+
3+
import "net/url"
4+
5+
// IsURL checks if a string is a valid URL
6+
func IsURL(input string) bool {
7+
parsed, err := url.Parse(input)
8+
return err == nil && parsed.Scheme != "" && parsed.Host != ""
9+
}

0 commit comments

Comments
 (0)