Skip to content

Commit 15c15d7

Browse files
committed
fix: support passing along URLs to the UI
Signed-off-by: tylerslaton <[email protected]>
1 parent affa1b7 commit 15c15d7

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

pkg/cli/gptscript.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,32 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
338338
return fmt.Errorf("chat UI only supports files, cannot read from stdin")
339339
}
340340

341-
absPathToScript, err := filepath.Abs(args[1])
342-
if err != nil {
343-
return fmt.Errorf("cannot determine absolute path to script %s: %v", args[1], err)
341+
file := args[1]
342+
343+
// If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
344+
// set it to the directory of the script and set the file to the base.
345+
external := strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "github.com")
346+
if !external {
347+
absPathToScript, err := filepath.Abs(args[1])
348+
if err != nil {
349+
return fmt.Errorf("cannot determine absolute path to script %s: %v", args[1], err)
350+
}
351+
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
352+
file = filepath.Base(args[1])
353+
} else {
354+
cwd, err := os.Getwd()
355+
if err != nil {
356+
return fmt.Errorf("could not determine current working directory: %w", err)
357+
}
358+
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+cwd)
344359
}
345360

346-
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
347361
if os.Getenv(system.BinEnvVar) == "" {
348362
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
349363
}
350364

351-
args = append([]string{args[0]}, "--file="+filepath.Base(args[1]))
365+
args = append([]string{args[0]}, "--file="+file)
366+
352367
if len(args) > 2 {
353368
args = append(args, args[2:]...)
354369
}

0 commit comments

Comments
 (0)