This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Harry Solovay <[email protected]>
- Loading branch information
1 parent
e514a59
commit c673026
Showing
7 changed files
with
109 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
import { CapiBinary } from "../deps/capi_binary_builds.ts" | ||
import { Command } from "../deps/cliffy.ts" | ||
|
||
export default async function( | ||
export const bin = new Command() | ||
.description("Execute <binary>@<version> with [args...]") | ||
.arguments("<binary:string> <version:string> [...args:string]") | ||
.stopEarly() | ||
.example("run a polkadot node in dev mode", "capi bin polkadot v0.9.41 --dev") | ||
.example( | ||
"build a chain spec for Rococo local", | ||
"capi bin polkadot v0.9.41 build-spec --chain rococo-local", | ||
) | ||
.action(runBin) | ||
|
||
async function runBin( | ||
_options: void, | ||
binary: string, | ||
version: string, | ||
...args: string[] | ||
) { | ||
if (!binary || !version) throw new Error("Must specify binary and version") | ||
|
||
const bin = new CapiBinary(binary, version) | ||
|
||
if (!(await bin.exists())) { | ||
console.error("Downloading", bin.key) | ||
await bin.download() | ||
} | ||
|
||
const child = new Deno.Command(bin.path, { | ||
args, | ||
stdin: "inherit", | ||
stdout: "inherit", | ||
stderr: "inherit", | ||
}).spawn() | ||
|
||
for (const signal of ["SIGTERM", "SIGINT"] satisfies Deno.Signal[]) { | ||
Deno.addSignalListener(signal, () => { | ||
child.kill(signal) | ||
}) | ||
} | ||
|
||
Deno.exit((await child.status).code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/command/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import "./deps/shims/register.ts" | ||
import { Command } from "./deps/cliffy.ts" | ||
|
||
import bin from "./cli/bin.ts" | ||
import serve from "./cli/serve.ts" | ||
import sync from "./cli/sync.ts" | ||
import { bin } from "./cli/bin.ts" | ||
import { serve } from "./cli/serve.ts" | ||
import { sync } from "./cli/sync.ts" | ||
|
||
const commands: Record<string, (...args: string[]) => void> = { bin, serve, sync } | ||
|
||
if (Deno.args[0]! in commands) { | ||
commands[Deno.args[0]!]!(...Deno.args.slice(1)) | ||
} else { | ||
throw new Error("Unrecognized command") | ||
} | ||
await new Command() | ||
.name("capi") | ||
.description("Capi is a framework for crafting interactions with Substrate chains") | ||
.command("bin", bin) | ||
.command("sync", sync) | ||
.command("serve", serve) | ||
.parse(Deno.args) |