Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lk): refer to projects by slug-name #432

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/lk/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
project *config.ProjectConfig
AppCommands = []*cli.Command{
{
Hidden: true,
Name: "app",
Category: "Core",
Commands: []*cli.Command{
Expand Down
6 changes: 5 additions & 1 deletion cmd/lk/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ func listProjects(ctx context.Context, cmd *cli.Command) error {
}).
Headers("Name", "URL", "API Key", "Default")
for _, p := range cliConfig.Projects {
table.Row(p.Name, p.URL, p.APIKey, fmt.Sprint(p.Name == cliConfig.DefaultProject))
name, err := p.URLSafeName()
if err != nil {
return err
}
table.Row(name, p.URL, p.APIKey, fmt.Sprint(p.Name == cliConfig.DefaultProject))
}
fmt.Println(table)

Expand Down
2 changes: 1 addition & 1 deletion cmd/lk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func loadProjectDetails(c *cli.Command, opts ...loadOption) (*config.ProjectConf
if err != nil {
return nil, err
}
fmt.Println("Using project:", c.String("project"))
fmt.Println("Using project [" + theme.Focused.Title.Render(c.String("project")) + "]")
logDetails(c, pc)
return pc, nil
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config
import (
"errors"
"fmt"
"net/url"
"os"
"path"
"strings"
Expand All @@ -38,6 +39,19 @@ type ProjectConfig struct {
APISecret string `yaml:"api_secret"`
}

func (p *ProjectConfig) URLSafeName() (string, error) {
parsed, err := url.Parse(p.URL)
if err != nil {
return "", errors.New("invalid URL")
}
subdomain := strings.Split(parsed.Hostname(), ".")[0]
lastHyphen := strings.LastIndex(subdomain, "-")
if lastHyphen == -1 {
return subdomain, nil
}
return subdomain[:lastHyphen], nil
}

func LoadDefaultProject() (*ProjectConfig, error) {
conf, err := LoadOrCreate()
if err != nil {
Expand Down Expand Up @@ -66,6 +80,9 @@ func LoadProject(name string) (*ProjectConfig, error) {
if p.Name == name {
return &p, nil
}
if prefix, _ := p.URLSafeName(); prefix == name {
return &p, nil
}
}

return nil, errors.New("project not found")
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
package livekitcli

const (
Version = "2.1.5"
Version = "2.2.0"
)
Loading