@@ -2,10 +2,12 @@ package cli
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
5
6
"os"
6
7
"strings"
7
8
8
9
"github.com/gptscript-ai/gptscript/pkg/input"
10
+ "github.com/gptscript-ai/gptscript/pkg/loader"
9
11
"github.com/gptscript-ai/gptscript/pkg/parser"
10
12
"github.com/spf13/cobra"
11
13
)
@@ -26,12 +28,28 @@ func locationName(l string) string {
26
28
}
27
29
28
30
func (e * Parse ) Run (_ * cobra.Command , args []string ) error {
29
- input , err := input .FromFile (args [0 ])
31
+ var (
32
+ content string
33
+ err error
34
+ )
35
+
36
+ // Attempt to read the file first, if that fails, try to load the URL. Finally,
37
+ // return an error if both fail.
38
+ content , err = input .FromFile (args [0 ])
30
39
if err != nil {
31
- return err
40
+ log .Debugf ("failed to read file %s (due to %v) attempting to load the URL..." , args [0 ], err )
41
+ content , err = loader .ContentFromURL (args [0 ])
42
+ if err != nil {
43
+ return err
44
+ }
45
+ // If the content is empty and there was no error, this is not a remote file. Return a generic
46
+ // error indicating that the file could not be loaded.
47
+ if content == "" {
48
+ return fmt .Errorf ("failed to load %v" , args [0 ])
49
+ }
32
50
}
33
51
34
- docs , err := parser .Parse (strings .NewReader (input ), parser.Options {
52
+ docs , err := parser .Parse (strings .NewReader (content ), parser.Options {
35
53
Location : locationName (args [0 ]),
36
54
})
37
55
if err != nil {
0 commit comments