Implemented error messages
This commit is contained in:
parent
423526e567
commit
e3b26c79f4
16 changed files with 362 additions and 60 deletions
|
@ -11,11 +11,12 @@ import (
|
|||
// Build builds an executable.
|
||||
func Build(args []string) int {
|
||||
b := build.New()
|
||||
writeExecutable := true
|
||||
|
||||
for i := 0; i < len(args); i++ {
|
||||
switch args[i] {
|
||||
case "--dry":
|
||||
b.WriteExecutable = false
|
||||
writeExecutable = false
|
||||
|
||||
case "--verbose", "-v":
|
||||
config.Verbose = true
|
||||
|
@ -34,7 +35,20 @@ func Build(args []string) int {
|
|||
b.Files = append(b.Files, ".")
|
||||
}
|
||||
|
||||
err := b.Run()
|
||||
result, err := b.Run()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if !writeExecutable {
|
||||
return 0
|
||||
}
|
||||
|
||||
path := b.Executable()
|
||||
code, data := build.Finalize(result)
|
||||
err = build.Write(path, code, data)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -6,7 +6,7 @@ import "fmt"
|
|||
func Help(args []string) int {
|
||||
fmt.Println("Usage: q [command] [options]")
|
||||
fmt.Println("")
|
||||
fmt.Println(" build [directory]")
|
||||
fmt.Println(" build [directory] [file]")
|
||||
fmt.Println(" system")
|
||||
return 2
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package cli_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/cli"
|
||||
|
@ -19,17 +17,16 @@ func TestCLI(t *testing.T) {
|
|||
{[]string{}, 2},
|
||||
{[]string{"invalid"}, 2},
|
||||
{[]string{"system"}, 0},
|
||||
{[]string{"build", "non-existing-directory"}, 1},
|
||||
{[]string{"build", "../../examples/hello/hello.q"}, 1},
|
||||
{[]string{"build", "invalid-directory"}, 1},
|
||||
{[]string{"build", "--invalid-parameter"}, 2},
|
||||
{[]string{"build", "../../examples/hello", "--invalid"}, 2},
|
||||
{[]string{"build", "../../examples/hello", "--dry"}, 0},
|
||||
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
|
||||
{[]string{"build", "../../examples/hello/hello.q", "--dry"}, 0},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Log(test.arguments)
|
||||
directory, _ := os.Getwd()
|
||||
fmt.Println(directory)
|
||||
exitCode := cli.Main(test.arguments)
|
||||
assert.Equal(t, exitCode, test.expectedExitCode)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue