This commit is contained in:
parent
8d13f1ece8
commit
f62657edde
2 changed files with 39 additions and 1 deletions
|
@ -11,6 +11,7 @@ func TestExec(t *testing.T) {
|
|||
assert.Equal(t, cli.Exec(nil), 2)
|
||||
assert.Equal(t, cli.Exec([]string{"_"}), 2)
|
||||
assert.Equal(t, cli.Exec([]string{"build"}), 1)
|
||||
assert.Equal(t, cli.Exec([]string{"run"}), 1)
|
||||
assert.Equal(t, cli.Exec([]string{"build", "--invalid-parameter"}), 2)
|
||||
assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "--invalid-parameter"}), 2)
|
||||
assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "--dry"}), 0)
|
||||
|
@ -21,5 +22,4 @@ func TestExec(t *testing.T) {
|
|||
assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "--dry", "--arch", "x86"}), 0)
|
||||
assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello/hello.q", "--dry"}), 0)
|
||||
assert.Equal(t, cli.Exec([]string{"help"}), 0)
|
||||
assert.Equal(t, cli.Exec([]string{"run"}), 0)
|
||||
}
|
|
@ -1,6 +1,44 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"git.urbach.dev/cli/q/src/compiler"
|
||||
"git.urbach.dev/cli/q/src/linker"
|
||||
)
|
||||
|
||||
// run builds and runs the executable.
|
||||
func run(args []string) int {
|
||||
b, err := newBuildFromArgs(args)
|
||||
|
||||
if err != nil {
|
||||
return exit(err)
|
||||
}
|
||||
|
||||
result, err := compiler.Compile(b)
|
||||
|
||||
if err != nil {
|
||||
return exit(err)
|
||||
}
|
||||
|
||||
err = linker.WriteFile(b.Executable(), b, result)
|
||||
|
||||
if err != nil {
|
||||
return exit(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(b.Executable())
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return exit(err)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue