Skip to content

Commit

Permalink
feat(lk): refer to projects by slug-name (#432)
Browse files Browse the repository at this point in the history
* chore(lk): unhide app subcommands

* feat(lk): use allow referring to project by slug-names

* chore(lk): bump version
  • Loading branch information
rektdeckard authored Oct 1, 2024
1 parent 18dab7e commit 5e8fed4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
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"
)

0 comments on commit 5e8fed4

Please sign in to comment.