diff --git a/cmd/lk/app.go b/cmd/lk/app.go index 6078defe..754991e7 100644 --- a/cmd/lk/app.go +++ b/cmd/lk/app.go @@ -40,7 +40,6 @@ var ( project *config.ProjectConfig AppCommands = []*cli.Command{ { - Hidden: true, Name: "app", Category: "Core", Commands: []*cli.Command{ diff --git a/cmd/lk/project.go b/cmd/lk/project.go index d55dd41d..e41c05ae 100644 --- a/cmd/lk/project.go +++ b/cmd/lk/project.go @@ -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) diff --git a/cmd/lk/utils.go b/cmd/lk/utils.go index 11108e1a..0da9584e 100644 --- a/cmd/lk/utils.go +++ b/cmd/lk/utils.go @@ -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 } diff --git a/pkg/config/config.go b/pkg/config/config.go index f098af33..de3b6ad4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,6 +17,7 @@ package config import ( "errors" "fmt" + "net/url" "os" "path" "strings" @@ -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 { @@ -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") diff --git a/version.go b/version.go index 39388c68..6af0fde6 100644 --- a/version.go +++ b/version.go @@ -15,5 +15,5 @@ package livekitcli const ( - Version = "2.1.5" + Version = "2.2.0" )