Skip to content

Commit b1cdd29

Browse files
committed
feat: add $.args
1 parent b3fa670 commit b1cdd29

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ script.
223223
- **flags:** Deno's `std/flags` module.
224224

225225
```ts
226-
console.log($.blue.bold("Hello world!"));
226+
const args: flags.Args = flags.parse($.args);
227227
```
228228

229229
## Variables
@@ -240,6 +240,8 @@ script.
240240
`"piped"`, `"null"` or `number`. Will be reverted to default after all async
241241
ops are done. Default: `"piped"`
242242
- **$.throwErrors:** Throw errors instead of calling `Deno.exit`.
243+
- **$.args:** Equivalent to `Deno.args`, but without the script name as first
244+
argument.
243245
- **$.startTime:** The execution start time in ms.
244246
- **$.time:** The time left since execution start (now() - $.startTime).
245247
- **$.quote:** Parser method that is used to safely quote strings. Used by:

src/cli/mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ export function dzx() {
6161
async (
6262
{ worker, ...perms },
6363
script?: string,
64-
_args?: Array<string>,
64+
args: Array<string> = [],
6565
) => {
66+
$.args = args;
6667
if (script) {
6768
$.mainModule = addProtocool(script);
6869
if (worker) {
@@ -90,6 +91,9 @@ export function dzx() {
9091
import "${new URL("./src/runtime/mod.ts", Deno.mainModule)}";
9192
$.mainModule = "${$.mainModule}";
9293
$.startTime = ${$.startTime};
94+
$.args = JSON.parse(decodeURIComponent("${
95+
encodeURIComponent(JSON.stringify($.args))
96+
}"));
9397
await import("${$.mainModule}");
9498
if ($.verbose) {
9599
const end = Date.now();

src/runtime/mod.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ export type $ = typeof exec & typeof colors & {
99
verbose: boolean;
1010
stdout: NonNullable<Deno.RunOptions["stdout"]>;
1111
stderr: NonNullable<Deno.RunOptions["stderr"]>;
12+
args: Array<string>;
13+
quote: typeof shq;
1214
throwErrors: boolean;
1315
startTime: number;
1416
time: number;
15-
quote: typeof shq;
1617
};
1718

1819
export const $: $ = exec as $;
@@ -25,6 +26,7 @@ $.mainModule = "";
2526
$.verbose = false;
2627
$.stdout = "piped";
2728
$.stderr = "piped";
29+
$.args = [];
2830
$.quote = shq;
2931
$.throwErrors = false;
3032
$.startTime = Date.now();

0 commit comments

Comments
 (0)