This commit is contained in:
commit
bc5530a70a
12 changed files with 125 additions and 0 deletions
22
src/cli/Exec.go
Normal file
22
src/cli/Exec.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package cli
|
||||
|
||||
// Exec runs the command included in the first argument and returns the exit code.
|
||||
func Exec(args []string) int {
|
||||
if len(args) == 0 {
|
||||
return invalid()
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
case "build":
|
||||
return build(args[1:])
|
||||
|
||||
case "run":
|
||||
return run(args[1:])
|
||||
|
||||
case "help":
|
||||
return help()
|
||||
|
||||
default:
|
||||
return invalid()
|
||||
}
|
||||
}
|
16
src/cli/Exec_test.go
Normal file
16
src/cli/Exec_test.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package cli_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.urbach.dev/cli/q/src/cli"
|
||||
"git.urbach.dev/go/assert"
|
||||
)
|
||||
|
||||
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"}), 0)
|
||||
assert.Equal(t, cli.Exec([]string{"run"}), 0)
|
||||
assert.Equal(t, cli.Exec([]string{"help"}), 0)
|
||||
}
|
6
src/cli/build.go
Normal file
6
src/cli/build.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package cli
|
||||
|
||||
// build parses the arguments and creates a build.
|
||||
func build(args []string) int {
|
||||
return 0
|
||||
}
|
16
src/cli/help.go
Normal file
16
src/cli/help.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed help.txt
|
||||
var helpText string
|
||||
|
||||
// help shows the command line argument usage.
|
||||
func help() int {
|
||||
fmt.Fprintln(os.Stdout, helpText)
|
||||
return 0
|
||||
}
|
9
src/cli/help.txt
Normal file
9
src/cli/help.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
Usage:
|
||||
|
||||
q [command] [options]
|
||||
|
||||
Commands:
|
||||
|
||||
build [directory | file] build an executable
|
||||
run [directory | file] build and run the executable
|
||||
help show this help
|
12
src/cli/invalid.go
Normal file
12
src/cli/invalid.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// invalid shows the help and returns exit code 2 (invalid parameters).
|
||||
func invalid() int {
|
||||
fmt.Fprintln(os.Stderr, helpText)
|
||||
return 2
|
||||
}
|
6
src/cli/run.go
Normal file
6
src/cli/run.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package cli
|
||||
|
||||
// run builds and runs the executable.
|
||||
func run(args []string) int {
|
||||
return 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue