From 15cb007ce73e3856c1ccda4ae65506b2d1271a4b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 22 Dec 2024 08:50:33 +0700 Subject: [PATCH 1/2] docs: add example with args-tokenizer As suggested in https://github.com/tinylibs/tinyexec/issues/42 added example to [args-tokenizer](https://github.com/TrySound/args-tokenizer) for parsing command and argument from strings. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index dc17106..880b4b2 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,24 @@ proc.aborted; // true proc.killed; // true ``` +### Using with args-tokenizer + +[args-tokenizer](https://github.com/TrySound/args-tokenizer) is a lightweight +library for parsing shell commands with arguments into an argv array. + +In this example, it is combined with tinyexec to execute a command from string. + +```ts +import {x} from 'tinyexec'; +import {tokenizeArgs} from 'args-tokenizer'; + +const commandString = 'echo "Hello, World!"'; +const [command, ...args] = tokenize(commandString); +const result = await x(command, args); + +result.stdout; // Hello, World! +``` + ## API Calling `x(command[, args])` returns an awaitable `Result` which has the From b2a359ac92b8cdb19b8d40681442a0e0dbf036f3 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 22 Dec 2024 18:02:25 +0700 Subject: [PATCH 2/2] Rephrase --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 880b4b2..6c012a9 100644 --- a/README.md +++ b/README.md @@ -124,12 +124,11 @@ proc.aborted; // true proc.killed; // true ``` -### Using with args-tokenizer +### Using with command strings -[args-tokenizer](https://github.com/TrySound/args-tokenizer) is a lightweight -library for parsing shell commands with arguments into an argv array. - -In this example, it is combined with tinyexec to execute a command from string. +If you need to continue supporting commands as strings (e.g. "command arg0 arg1"), +you can use [args-tokenizer](https://github.com/TrySound/args-tokenizer), +a lightweight library for parsing shell command strings into an array. ```ts import {x} from 'tinyexec';