This commit is contained in:
commit
bc5530a70a
12 changed files with 125 additions and 0 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
*
|
||||
!*/
|
||||
!*.q
|
||||
!*.go
|
||||
!*.mod
|
||||
!*.sum
|
||||
!*.md
|
||||
!*.txt
|
||||
!.gitignore
|
11
docs/readme.md
Normal file
11
docs/readme.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# q
|
||||
|
||||
A programming language that quickly compiles to machine code.
|
||||
|
||||
## License
|
||||
|
||||
Please see the [license documentation](https://urbach.dev/license).
|
||||
|
||||
## Copyright
|
||||
|
||||
© 2025 Eduard Urbach
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module git.urbach.dev/cli/q
|
||||
|
||||
go 1.24
|
||||
|
||||
require git.urbach.dev/go/assert v0.0.0-20250606150337-559d3d3afcda
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
git.urbach.dev/go/assert v0.0.0-20250606150337-559d3d3afcda h1:VN6ZQwtwLOm2xTms+v8IIeeNjvs55qyEBNArv3dPq9g=
|
||||
git.urbach.dev/go/assert v0.0.0-20250606150337-559d3d3afcda/go.mod h1:PNI/NSBOqvoeU58/7eBsIR09Yoq2S/qtSRiTrctkiq0=
|
11
main.go
Normal file
11
main.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.urbach.dev/cli/q/src/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(cli.Exec(os.Args[1:]))
|
||||
}
|
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