lang: gapi: Convenience the user by allowing relative dirs in cli

This commit is contained in:
James Shubin
2024-11-28 17:25:32 -05:00
parent e1070d3e13
commit 8472b1ebf2

View File

@@ -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