2023-11-17 12:47:37 +00:00
|
|
|
package labs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/cmd/labs/github"
|
|
|
|
"github.com/databricks/cli/cmd/labs/project"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type labsMeta struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
License string `json:"license"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func allRepos(ctx context.Context) (github.Repositories, error) {
|
2023-11-29 19:08:27 +00:00
|
|
|
cacheDir, err := project.PathInLabs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-11-17 12:47:37 +00:00
|
|
|
cache := github.NewRepositoryCache("databrickslabs", cacheDir)
|
|
|
|
return cache.Load(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newListCommand() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "List all labs",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"template": cmdio.Heredoc(`
|
|
|
|
Name Description
|
|
|
|
{{range .}}{{.Name}} {{.Description}}
|
|
|
|
{{end}}
|
|
|
|
`),
|
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
ctx := cmd.Context()
|
|
|
|
repositories, err := allRepos(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
info := []labsMeta{}
|
|
|
|
for _, v := range repositories {
|
|
|
|
if v.IsArchived {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if v.IsFork {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
description := v.Description
|
|
|
|
if len(description) > 50 {
|
|
|
|
description = description[:50] + "..."
|
|
|
|
}
|
|
|
|
info = append(info, labsMeta{
|
|
|
|
Name: v.Name,
|
|
|
|
Description: description,
|
|
|
|
License: v.License.Name,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return cmdio.Render(ctx, info)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|