Skip to content

Commit 7ebe198

Browse files
committed
♻️ examples/cli 🐛 xarg
1 parent 39e9587 commit 7ebe198

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

examples/cli.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#!/usr/bin/env nodejsscript
2-
import { cli, echo, mkdir, pipe, rm, tempdir, test } from "nodejsscript";
2+
import { cli, echo, mkdir, pipe, rm, tempdir, test, xarg } from "nodejsscript";
33
import { join } from "node:path";
44

55
cli("", true)
66
.version("0.1.0")
77
.describe("NodeJS Script cli test")
88
.option("--clear", "Clears cerated temp dir")
9-
.action(async function main({ clear }){
10-
const name= join(tempdir, "foo bar");
11-
pipe(mkdir, echo)(name);
12-
echo(test("-d", name));
9+
.action(function main({ clear }){
10+
const name= join(tempdir(), "foo bar");
11+
mkdir("-p", name);
1312

14-
if(clear)
15-
rm("-R", name);
16-
echo(test("-d", name));
13+
const testDir= pipe(xarg(test, "-d"), echo);
14+
testDir(name);
15+
16+
if(clear) rm("-R", name);
17+
testDir(name);
1718
})
1819
.parse(process.argv);

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function xarg(...params){
1616
return function call(arg){
1717
let replaced= 0;
1818
const args_final= args.map(a=> a.replaceAll(needle, ()=> ( replaced+= 1, arg )));
19-
if(!replaced) args.push(arg);
19+
if(!replaced) args_final.push(arg);
2020
return cmd.apply(null, args_final);
2121
};
2222
}

0 commit comments

Comments
 (0)