From 8472b1ebf2092513e532e164a5ec6f35d6b1855f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 28 Nov 2024 17:25:32 -0500 Subject: [PATCH] lang: gapi: Convenience the user by allowing relative dirs in cli --- lang/gapi/gapi.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lang/gapi/gapi.go b/lang/gapi/gapi.go index 1cb85f15..1013f140 100644 --- a/lang/gapi/gapi.go +++ b/lang/gapi/gapi.go @@ -34,6 +34,8 @@ import ( "bytes" "context" "fmt" + "os" + "path/filepath" "strings" "sync" "time" @@ -117,8 +119,15 @@ func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) { // empty by default (don't set for deploy, only download) modules := args.ModulePath - if modules != "" && (!strings.HasPrefix(modules, "/") || !strings.HasSuffix(modules, "/")) { - return nil, fmt.Errorf("module path is not an absolute directory") + if modules != "" && !strings.HasSuffix(modules, "/") { + return nil, fmt.Errorf("module path does not end with a slash") + } + if modules != "" && !strings.HasPrefix(modules, "/") { + wd, err := os.Getwd() + if err != nil { + return nil, err + } + modules = filepath.Join(wd, modules) + "/" } // TODO: while reading through trees of metadata files, we could also