Skip to content

Commit a5659b2

Browse files
justjoheinzjeswr
andauthored
chore(docs): add help command and fix CLI usage examples (#1016)
* feat: add help command and fix CLI usage examples - Add --help flag and help text to swipl-generate CLI - Update README to use correct npx swipl-generate command syntax * feat: update help text to mention only TypeScript generation Changes CLI help text to specify TypeScript output only, removing JavaScript option from usage examples and argument descriptions. --------- Co-authored-by: Jesse Wright <63333554+jeswr@users.noreply.github.com>
1 parent f7e74ba commit a5659b2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ the `.js` file instead.
100100

101101
## Generating an image
102102

103-
Often you will want to bundle a pre-built image of your Prolog file. The easiest way to do this is using the `swipl-generate` command to generate the image. For example in `./examples/generation` the script: `swipl-generate ./max.pl ./dist/max.ts` will generate a file `./dist/max.ts` which contains the image of `./max.pl`. This file can then be imported into your project and used as follows:
103+
Often you will want to bundle a pre-built image of your Prolog file. The easiest way to do this is using the `swipl-generate` command to generate the image. For example in `./examples/generation` the script: `npx swipl-generate ./max.pl ./dist/max.ts` will generate a file `./dist/max.ts` which contains the image of `./max.pl`. This file can then be imported into your project and used as follows:
104104

105105
```ts
106106
import SWIPL from './max';

dist/bin/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
const { generateLoadedImageFile, generateImageFile } = require('../generateImage')
44
const path = require('path');
55

6+
function showHelp() {
7+
console.log(`Usage: swipl-generate <input.pl> <output.ts> [--image-only]
8+
9+
Arguments:
10+
input.pl Prolog source file or HTTP(S) URL
11+
output.ts Output TypeScript file
12+
13+
Options:
14+
--image-only Generate image data only
15+
--help Show this help`);
16+
}
17+
618
function getPath(pth) {
719
return pth.startsWith('http://') || pth.startsWith('https://')
820
? pth
@@ -12,6 +24,12 @@ function getPath(pth) {
1224
async function mainFunc() {
1325
let args = process.argv.slice(2);
1426

27+
// Check for help flag or no arguments
28+
if (args.includes('--help') || args.includes('-h') || args.length === 0) {
29+
showHelp();
30+
return;
31+
}
32+
1533
const fn = process.argv.includes('--image-only') ? generateImageFile : generateLoadedImageFile;
1634
args = args.filter(elem => elem !== '--image-only');
1735

0 commit comments

Comments
 (0)