Skip to content

Commit

Permalink
feat: add license and --version -v (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
puria authored Jun 12, 2024
1 parent 492e0c5 commit fa2c6f0
Show file tree
Hide file tree
Showing 7 changed files with 715 additions and 203 deletions.
Binary file modified bun.lockb
Binary file not shown.
863 changes: 661 additions & 202 deletions license

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "slangroom-exec",
"module": "index.ts",
"license": "AGPL-3.0-or-later",
"type": "module",
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
Expand Down
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
import { slangroom_exec } from "./lib";
const packageJson = require("../package.json");

const argv = Bun.argv;

if (argv.includes("-v") || argv.includes("--version")) {
console.log(`${packageJson.name} ${packageJson.version}`);
console.error(`
_
| |
___| | _____ ____ ____ ____ ___ ___ ____ _____ _____ _ _ _____ ____
/___) |(____ | _ \ / _ |/ ___) _ \ / _ \| (_____) ___ ( \ / ) ___ |/ ___)
|___ | |/ ___ | | | ( (_| | | | |_| | |_| | | | | | ____|) X (| ____( (___
(___/ \_)_____|_| |_|\___ |_| \___/ \___/|_|_|_| |_____|_/ \_)_____)\____)
(_____|
`)
console.error(`Built for ${process.platform}-${process.arch}
Copyright (C) 2024 ${packageJson.author}
License AGPL-3.0-or-later: GNU AGPL version 3 <https://www.gnu.org/licenses/agpl-3.0.html>
This is free software: you are free to change and redistribute it
There is NO WARRANTY, to the extent permitted by law.`);
process.exit(0);
}

if (argv.includes("-h") || argv.includes("--help")) {
console.log(`Usage: cat <encoded_input> | ${packageJson.name} [options]
Options:
-v, --version Show version
-h, --help Show this help message`);
process.exit(0);
}

const the_input = await Bun.stdin.text();
const the_output = await slangroom_exec(the_input);
Expand Down
20 changes: 19 additions & 1 deletion test/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setup() {
assert_success
}

@test "should fail on empty slangroom" {
@test "should fail on empty or broken contract" {
load_fixture "broken_conf"
run_slangroom_exec
assert_output "Malformed input: Slangroom contract is empty"
Expand All @@ -49,3 +49,21 @@ setup() {
assert_output --partial "Invalid Zencode prefix 1: 'Gibberish'"
assert_failure 1
}

@test "should fail on empty contract" {
load_fixture "empty"
run_slangroom_exec
assert_output "Malformed input: Slangroom contract is empty"
assert_failure 1
}

@test "should show the version and header" {
run ./slangroom-exec -v
assert_output --partial "License AGPL-3.0-or-later: GNU AGPL version 3 <https://www.gnu.org/licenses/agpl-3.0.html>"
assert_output --partial "Copyright (C) 2024 undefined"
assert_output --partial "slangroom-exec"
run ./slangroom-exec --version
assert_output --partial "License AGPL-3.0-or-later: GNU AGPL version 3 <https://www.gnu.org/licenses/agpl-3.0.html>"
assert_output --partial "Copyright (C) 2024 undefined"
assert_output --partial "slangroom-exec"
}
4 changes: 4 additions & 0 deletions test/fixtures/broken.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rule unknown ignore
Given I fetch the local timestamp in seconds and output into 'timestamp'
Given I have a 'time' named 'timestamp'
Then print the 'timestamp'
Empty file added test/fixtures/empty.slang
Empty file.

0 comments on commit fa2c6f0

Please sign in to comment.