From 8e7870ec6e8e38c8ac1b706c2049d8f862d1c9f2 Mon Sep 17 00:00:00 2001 From: Manuel Odendahl Date: Wed, 5 Jul 2023 16:31:35 -0400 Subject: [PATCH] :art: Adapt to new clay APIs --- pkg/handlers/command-dir/command-dir.go | 9 +++++---- pkg/handlers/config-file.go | 18 +++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pkg/handlers/command-dir/command-dir.go b/pkg/handlers/command-dir/command-dir.go index 0359b59..7518298 100644 --- a/pkg/handlers/command-dir/command-dir.go +++ b/pkg/handlers/command-dir/command-dir.go @@ -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" @@ -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{} @@ -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 } @@ -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 } diff --git a/pkg/handlers/config-file.go b/pkg/handlers/config-file.go index 6f8deed..d4f7898 100644 --- a/pkg/handlers/config-file.go +++ b/pkg/handlers/config-file.go @@ -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" @@ -28,16 +28,16 @@ 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). @@ -45,7 +45,7 @@ func NewRepositoryFactoryFromLoaders( // 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). @@ -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()