6
6
7
7
"github.com/spf13/cobra"
8
8
"github.com/vknabel/lithia"
9
+ "github.com/vknabel/lithia/potfile"
9
10
"github.com/vknabel/lithia/world"
10
11
)
11
12
@@ -14,24 +15,39 @@ func init() {
14
15
}
15
16
16
17
var runCmd = & cobra.Command {
17
- Use : "run [script]" ,
18
- Short : "Runs a Lithia script" ,
19
- Args : cobra .MinimumNArgs (1 ),
18
+ Use : "run [script]" ,
19
+ Short : "Runs a Lithia script" ,
20
+ Args : cobra .MinimumNArgs (1 ),
21
+ DisableFlagParsing : true ,
20
22
Run : func (cmd * cobra.Command , args []string ) {
21
- runFile (args [0 ], args )
23
+ world .Current .Args = args
24
+
25
+ firstArg := args [0 ]
26
+ potfileState , err := potfile .ForReferenceFile (firstArg )
27
+ if err != nil {
28
+ fmt .Fprint (world .Current .Stderr , err )
29
+ world .Current .Env .Exit (1 )
30
+ }
31
+
32
+ if potCmd , ok := potfileState .Cmds [firstArg ]; ok {
33
+ potCmd .RunCmd (args [1 :])
34
+ return
35
+ }
36
+
37
+ runFile (firstArg , args )
22
38
},
23
39
}
24
40
25
41
func runFile (fileName string , args []string ) {
26
- world .Current .Args = args
27
42
scriptData , err := world .Current .FS .ReadFile (fileName )
28
43
if err != nil {
29
44
fmt .Fprint (world .Current .Stderr , err )
30
45
world .Current .Env .Exit (1 )
31
46
}
32
47
inter := lithia .NewDefaultInterpreter (path .Dir (fileName ))
33
- script := string (scriptData ) + " \n "
48
+ script := string (scriptData )
34
49
_ , err = inter .Interpret (fileName , script )
50
+
35
51
if err != nil {
36
52
fmt .Fprint (world .Current .Stderr , err )
37
53
world .Current .Env .Exit (1 )
0 commit comments