commit bc5530a70a90d5f6479af3ee1eb12c10fa40cb11 Author: Eduard Urbach Date: Wed Jun 18 22:18:31 2025 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b71d4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +* +!*/ +!*.q +!*.go +!*.mod +!*.sum +!*.md +!*.txt +!.gitignore \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..dc56d25 --- /dev/null +++ b/docs/readme.md @@ -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 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9592327 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.urbach.dev/cli/q + +go 1.24 + +require git.urbach.dev/go/assert v0.0.0-20250606150337-559d3d3afcda \ No newline at end of file diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1b21880 --- /dev/null +++ b/go.sum @@ -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= \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..e303fb0 --- /dev/null +++ b/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "os" + + "git.urbach.dev/cli/q/src/cli" +) + +func main() { + os.Exit(cli.Exec(os.Args[1:])) +} \ No newline at end of file diff --git a/src/cli/Exec.go b/src/cli/Exec.go new file mode 100644 index 0000000..901fd9d --- /dev/null +++ b/src/cli/Exec.go @@ -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() + } +} \ No newline at end of file diff --git a/src/cli/Exec_test.go b/src/cli/Exec_test.go new file mode 100644 index 0000000..103e13f --- /dev/null +++ b/src/cli/Exec_test.go @@ -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) +} \ No newline at end of file diff --git a/src/cli/build.go b/src/cli/build.go new file mode 100644 index 0000000..46fd1ab --- /dev/null +++ b/src/cli/build.go @@ -0,0 +1,6 @@ +package cli + +// build parses the arguments and creates a build. +func build(args []string) int { + return 0 +} \ No newline at end of file diff --git a/src/cli/help.go b/src/cli/help.go new file mode 100644 index 0000000..3d02124 --- /dev/null +++ b/src/cli/help.go @@ -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 +} \ No newline at end of file diff --git a/src/cli/help.txt b/src/cli/help.txt new file mode 100644 index 0000000..ebe1173 --- /dev/null +++ b/src/cli/help.txt @@ -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 \ No newline at end of file diff --git a/src/cli/invalid.go b/src/cli/invalid.go new file mode 100644 index 0000000..1a18c33 --- /dev/null +++ b/src/cli/invalid.go @@ -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 +} \ No newline at end of file diff --git a/src/cli/run.go b/src/cli/run.go new file mode 100644 index 0000000..25d8377 --- /dev/null +++ b/src/cli/run.go @@ -0,0 +1,6 @@ +package cli + +// run builds and runs the executable. +func run(args []string) int { + return 0 +} \ No newline at end of file