Skip to content

Commit d15c4e9

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

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/cli/gptscript.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,31 @@ 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+
if !(strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "github.com")) {
346+
absPathToScript, err := filepath.Abs(file)
347+
if err != nil {
348+
return fmt.Errorf("cannot determine absolute path to script %s: %v", file, err)
349+
}
350+
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
351+
file = filepath.Base(file)
352+
} else {
353+
cwd, err := os.Getwd()
354+
if err != nil {
355+
return fmt.Errorf("could not determine current working directory: %w", err)
356+
}
357+
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+cwd)
344358
}
345359

346-
gptOpt.Env = append(gptOpt.Env, "SCRIPTS_PATH="+filepath.Dir(absPathToScript))
347360
if os.Getenv(system.BinEnvVar) == "" {
348361
gptOpt.Env = append(gptOpt.Env, system.BinEnvVar+"="+system.Bin())
349362
}
350363

351-
args = append([]string{args[0]}, "--file="+filepath.Base(args[1]))
364+
args = append([]string{args[0]}, "--file="+file)
365+
352366
if len(args) > 2 {
353367
args = append(args, args[2:]...)
354368
}

0 commit comments

Comments
 (0)