Skip to content

Commit

Permalink
🎨 Adapt to new clay APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Jul 5, 2023
1 parent 5b8a2ff commit 8e7870e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions pkg/handlers/command-dir/command-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-go-golems/clay/pkg/repositories"
"github.com/go-go-golems/clay/pkg/repositories/fs"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/layers"
"github.com/go-go-golems/parka/pkg/glazed/handlers/datatables"
Expand Down Expand Up @@ -89,7 +90,7 @@ type CommandDirHandler struct {
TemplateLookup render.TemplateLookup

// Repository is the command repository that is exposed over HTTP through this handler.
Repository *repositories.Repository
Repository *fs.Repository

// AdditionalData is passed to the template being rendered.
AdditionalData map[string]interface{}
Expand Down Expand Up @@ -304,7 +305,7 @@ func WithDevMode(devMode bool) CommandDirHandlerOption {
}
}

func WithRepository(r *repositories.Repository) CommandDirHandlerOption {
func WithRepository(r *fs.Repository) CommandDirHandlerOption {
return func(handler *CommandDirHandler) {
handler.Repository = r
}
Expand Down Expand Up @@ -507,9 +508,9 @@ func (cd *CommandDirHandler) Serve(server *parka.Server, path string) error {
// or sends an error code over HTTP using the gin.Context.
//
// TODO(manuel, 2023-05-31) This is an odd API, is it necessary?
func getRepositoryCommand(c *gin.Context, r *repositories.Repository, commandPath string) (cmds.GlazeCommand, bool) {
func getRepositoryCommand(c *gin.Context, r repositories.Repository, commandPath string) (cmds.GlazeCommand, bool) {
path := strings.Split(commandPath, "/")
commands := r.Root.CollectCommands(path, false)
commands := r.CollectCommands(path, false)
if len(commands) == 0 {
return nil, false
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/handlers/config-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"context"
"fmt"
"github.com/go-go-golems/clay/pkg/repositories"
"github.com/go-go-golems/clay/pkg/repositories/fs"
"github.com/go-go-golems/glazed/pkg/cmds"
"github.com/go-go-golems/glazed/pkg/cmds/loaders"
"github.com/go-go-golems/glazed/pkg/helpers/strings"
Expand All @@ -28,24 +28,24 @@ import (

// RepositoryFactory is a function that returns a repository given a list of directories.
// This is used to provision the CommandDir handlers.
type RepositoryFactory func(dirs []string) (*repositories.Repository, error)
type RepositoryFactory func(dirs []string) (*fs.Repository, error)

func NewRepositoryFactoryFromLoaders(
commandLoader loaders.ReaderCommandLoader,
fsLoader loaders.FSCommandLoader,
) RepositoryFactory {
return func(dirs []string) (*repositories.Repository, error) {
r := repositories.NewRepository(
repositories.WithDirectories(dirs),
repositories.WithUpdateCallback(func(cmd cmds.Command) error {
return func(dirs []string) (*fs.Repository, error) {
r := fs.NewRepository(
fs.WithDirectories(dirs),
fs.WithUpdateCallback(func(cmd cmds.Command) error {
description := cmd.Description()
log.Info().Str("name", description.Name).
Str("source", description.Source).
Msg("Updating cmd")
// TODO(manuel, 2023-04-19) This is where we would recompute the HandlerFunc used below in GET and POST
return nil
}),
repositories.WithRemoveCallback(func(cmd cmds.Command) error {
fs.WithRemoveCallback(func(cmd cmds.Command) error {
description := cmd.Description()
log.Info().Str("name", description.Name).
Str("source", description.Source).
Expand All @@ -55,8 +55,8 @@ func NewRepositoryFactoryFromLoaders(
// We don't need to recompute the func, since it fetches the command at runtime.
return nil
}),
repositories.WithCommandLoader(commandLoader),
repositories.WithFSLoader(fsLoader),
fs.WithCommandLoader(commandLoader),
fs.WithFSLoader(fsLoader),
)

err := r.LoadCommands()
Expand Down

0 comments on commit 8e7870e

Please sign in to comment.