{"id":15374165,"url":"https://github.com/stil/deno_cliwrap","last_synced_at":"2026-03-17T23:30:19.224Z","repository":{"id":41487176,"uuid":"509856475","full_name":"stil/deno_cliwrap","owner":"stil","description":"Convenient wrapper for launching CLI applications for Deno.","archived":false,"fork":false,"pushed_at":"2022-07-03T01:43:50.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-23T00:16:08.234Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-02T20:34:58.000Z","updated_at":"2022-07-02T23:59:13.000Z","dependencies_parsed_at":"2022-09-21T10:23:42.834Z","dependency_job_id":null,"html_url":"https://github.com/stil/deno_cliwrap","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fdeno_cliwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fdeno_cliwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fdeno_cliwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stil%2Fdeno_cliwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stil","download_url":"https://codeload.github.com/stil/deno_cliwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239929201,"owners_count":19720086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:57:28.042Z","updated_at":"2026-03-17T23:30:19.192Z","avatar_url":"https://github.com/stil.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deno_cliwrap\n\nConvenient wrapper for launching CLI applications in Deno.\n\nModule link: https://deno.land/x/cliwrap\n\n# Usage\n\nIn the following examples, we'll use `deno` executable as it's safe to assume you're familiar with it and you have it already installed.\n\n### Detect deno executable version\n\nWe'll call `deno -V` and capture standard output.\n\n```ts\nimport {\n  Cli,\n  createPipeTargetToDelegate,\n} from \"https://deno.land/x/cliwrap/mod.ts\";\n\nlet stdout = \"\";\nconst cmd = Cli.wrap(\"deno\")\n  .withArguments([\"-V\"])\n  .withStandardOutputPipe(\n    createPipeTargetToDelegate((data) =\u003e {\n      stdout += data.text;\n      if (data.eol) {\n        stdout += \"\\r\\n\";\n      }\n    })\n  )\n  .execute();\n\nawait cmd.waitForExit();\nconsole.log(stdout); // deno 1.23.2\n```\n\n### Evaluate any code in Deno runtime\n\nWe'll call `deno run -`, where '-' means that script will be read from stdin.\n\n```ts\nimport {\n  Cli,\n  createPipeSourceFromString,\n  createPipeTargetToDelegate,\n} from \"https://deno.land/x/cliwrap/mod.ts\";\n\nconst fnText = `console.log('Hello World'.replace('o', ''));`;\n\nlet stdout = \"\";\nconst cmd = Cli.wrap(\"deno\")\n  .withArguments([\"run\", \"-\"])\n  .withStandardInputPipe(createPipeSourceFromString(fnText))\n  .withStandardOutputPipe(\n    createPipeTargetToDelegate((data) =\u003e {\n      stdout += data.text;\n      if (data.eol) {\n        stdout += \"\\r\\n\";\n      }\n    })\n  )\n  .execute();\n\nconst cmdResult = await cmd.waitForExit();\n\nconsole.log(cmdResult.code); // 0 - success\nconsole.log(stdout); // \"Hell World\"\n```\n\n### Capture stderr\n\nWe'll call `deno run` but with a script that contains syntax error. Our goal is to capture error message.\n\n```ts\nimport {\n  Cli,\n  CommandResultValidation,\n  createPipeSourceFromString,\n  createPipeTargetToDelegate,\n} from \"https://deno.land/x/cliwrap/mod.ts\";\n\nconst fnText = `console.log('Hello World'.eplace('o', ''));`;\n\nlet stderr = \"\";\nconst cmd = Cli.wrap(\"deno\")\n  .withArguments([\"run\", \"-\"])\n  .withStandardInputPipe(createPipeSourceFromString(fnText))\n  .withStandardErrorPipe(\n    createPipeTargetToDelegate((data) =\u003e {\n      stderr += data.text;\n      if (data.eol) {\n        stderr += \"\\r\\n\";\n      }\n    })\n  )\n  .withValidation(CommandResultValidation.None) // Required to prevent throwing Error\n  .execute();\n\nconst cmdResult = await cmd.waitForExit();\n\nconsole.log(cmdResult.code); // 1 - error\nconsole.log(stderr); // error: Uncaught TypeError: \"Hello World\".eplace is not a function\n```\n\n### Advanced: talk to SSH server\n\nIn this example, we'll talk to SSH server via `plink.exe`.\n\n```ts\nimport {\n  Cli,\n  CommandResultValidation,\n  createLivePipeSource,\n  createRedirectedPipes,\n} from \"https://deno.land/x/cliwrap/mod.ts\";\n\nconst target = \"comet@192.168.1.110\";\nconst password = \"secretpassword\";\n\nconst stdin = createLivePipeSource();\nlet out = \"\";\nlet loggedIn = false;\nconst outPipes = createRedirectedPipes(\"server\", ({ text, eol }) =\u003e {\n  out += text;\n  if (eol) {\n    out += \"\\r\\n\";\n  }\n\n  if (\n    !loggedIn \u0026\u0026\n    out.endsWith(\n      \"Store key in cache? (y/n, Return cancels connection, i for more info) \"\n    )\n  ) {\n    stdin.write(\"n\\n\");\n  }\n\n  if (!loggedIn \u0026\u0026 out.endsWith(target + \"'s password: \")) {\n    loggedIn = true;\n    stdin.write(password + \"\\r\\n\");\n  }\n\n  if (loggedIn \u0026\u0026 out.endsWith(\"~]$ \")) {\n    stdin.write(\"exit\\n\");\n  }\n});\n\nconst cmd = Cli.wrap(\"plink\")\n  .withArguments([target])\n  .withStandardInputPipe(stdin)\n  .withStandardOutputPipe(outPipes.stdout)\n  .withStandardErrorPipe(outPipes.stderr)\n  .execute();\n\nawait cmd.waitForExit();\n\n// Example output:\n// ----\n// server# The host key is not cached for this server:\n// server#   192.168.1.110 (port 22)\n// server# You have no guarantee that the server is the computer\n// server# you think it is.\n// server# The server's ssh-ed25519 key fingerprint is:\n// server#   ssh-ed25519 255 SHA256:XXXXXXXXXXXXXXXXXXXXXXX\n// server# If you trust this host, enter \"y\" to add the key to\n// server# PuTTY's cache and carry on connecting.\n// server# If you want to carry on connecting just once, without\n// server# adding the key to the cache, enter \"n\".\n// server# If you do not trust this host, press Return to abandon the\n// server# connection.\n// server# Store key in cache? (y/n, Return cancels connection, i for more info) Using username \"comet\".\n// server\u003e comet@192.168.1.110's password:\n// server\u003e Web console: https://comet:9090/\n// server\u003e\n// server\u003e Last login: Sun Jul  3 00:00:00 2022 from 192.168.1.100\n// server\u003e [comet@comet ~]$ exit\n// logout\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstil%2Fdeno_cliwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstil%2Fdeno_cliwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstil%2Fdeno_cliwrap/lists"}