Skip to content

Commit 3dfcc41

Browse files
committed
refactor(pkg): factor out subdomain extraction fn
1 parent 0094159 commit 3dfcc41

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

cmd/lk/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func requireProject(ctx context.Context, cmd *cli.Command) (context.Context, err
153153
if len(cliConfig.Projects) > 0 {
154154
var options []huh.Option[*config.ProjectConfig]
155155
for _, p := range cliConfig.Projects {
156-
options = append(options, huh.NewOption(p.Name+" ["+p.APIKey+"]", &p))
156+
options = append(options, huh.NewOption(p.Name+" ["+util.ExtractSubdomain(p.URL)+"]", &p))
157157
}
158158
if err = huh.NewForm(
159159
huh.NewGroup(huh.NewSelect[*config.ProjectConfig]().

pkg/config/config.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
"fmt"
2020
"os"
2121
"path"
22-
"regexp"
2322
"strings"
2423

24+
"github.com/livekit/livekit-cli/v2/pkg/util"
2525
"gopkg.in/yaml.v3"
2626
)
2727

@@ -70,17 +70,8 @@ func LoadProjectBySubdomain(subdomain string) (*ProjectConfig, error) {
7070

7171
fmt.Println("Loading project by subdomain", subdomain)
7272

73-
extractSubdomain := func(url string) string {
74-
subdomainPattern := regexp.MustCompile(`^(?:https?|wss?)://([^.]+)\.`)
75-
matches := subdomainPattern.FindStringSubmatch(url)
76-
if len(matches) > 1 {
77-
return matches[1]
78-
}
79-
return ""
80-
}
81-
8273
for _, p := range conf.Projects {
83-
projectSubdomain := extractSubdomain(p.URL)
74+
projectSubdomain := util.ExtractSubdomain(p.URL)
8475
if projectSubdomain == subdomain {
8576
return &p, nil
8677
}

pkg/util/url.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package util
2+
3+
import (
4+
"regexp"
5+
)
6+
7+
func ExtractSubdomain(url string) string {
8+
subdomainPattern := regexp.MustCompile(`^(?:https?|wss?)://([^.]+)\.`)
9+
matches := subdomainPattern.FindStringSubmatch(url)
10+
if len(matches) > 1 {
11+
return matches[1]
12+
}
13+
return ""
14+
}

0 commit comments

Comments
 (0)