diff --git a/.circleci/config.yml b/.circleci/config.yml index df705c05..2ff4af33 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -139,6 +139,18 @@ jobs: environment: SKIP_BUILD: 1 command: yarn selftest + - run: + name: Run CLI examples + working_directory: packages/cli + environment: + SKIP_BUILD: 1 + command: | + ./bin/cosmwasm-cli --init examples/delegate.ts --code "process.exit(0)" + ./bin/cosmwasm-cli --init examples/faucet_addresses.ts --code "process.exit(0)" + ./bin/cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)" + ./bin/cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)" + ./bin/cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)" + ./bin/cosmwasm-cli --init examples/mask.ts --code "process.exit(0)" - run: command: ./scripts/wasmd/stop.sh - run: diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ceaf4b..d93bf727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## HEAD +- @cosmjs/cli: Now supports HTTPs URLs for `--init` code sources. +- @cosmjs/cli: Now supports adding code directly via `--code`. - @cosmjs/cosmwasm: Rename `CosmWasmClient.getNonce` method to `.getSequence`. - @cosmjs/cosmwasm: Remove `RestClient` class in favour of new modular `LcdClient` class from @cosmjs/sdk38. diff --git a/packages/cli/examples/faucet_addresses.ts b/packages/cli/examples/faucet_addresses.ts index 211ff61f..2e080c11 100644 --- a/packages/cli/examples/faucet_addresses.ts +++ b/packages/cli/examples/faucet_addresses.ts @@ -5,5 +5,5 @@ for (let i of [0, 1, 2, 3, 4]) { const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, makeCosmoshubPath(i), "cosmos"); const [{ address, pubkey }] = await wallet.getAccounts(); console.info(`Address ${i}: ${address}`); - console.info(`Pubkey ${i}: ${pubkey}`); + console.info(`Pubkey ${i}: ${toBase64(pubkey)}`); } diff --git a/packages/cli/examples/generate_address.ts b/packages/cli/examples/generate_address.ts index cbf7ae95..9e403284 100644 --- a/packages/cli/examples/generate_address.ts +++ b/packages/cli/examples/generate_address.ts @@ -3,5 +3,5 @@ const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic); const [{ address, pubkey }] = await wallet.getAccounts(); console.info("mnemonic:", mnemonic); -console.info("pubkey:", pubkey); +console.info("pubkey:", encodeSecp256k1Pubkey(pubkey)); console.info("address:", address); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 1bee333e..b256d2f4 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -1,3 +1,4 @@ +import axios from "axios"; import * as fs from "fs"; import { join } from "path"; import yargs from "yargs"; @@ -6,12 +7,18 @@ import { TsRepl } from "./tsrepl"; import colors = require("colors/safe"); -export function main(originalArgs: readonly string[]): void { +export async function main(originalArgs: readonly string[]): Promise { const args = yargs .options({ // User options (we get --help and --version for free) init: { - describe: "Read initial TypeScript code from files", + describe: + "Read initial TypeScript code from the given sources. This can be URLs (supported schemes: https) or local file paths.", + type: "array", + }, + code: { + describe: + "Add initial TypeScript code from the argument. All code arguments are processed after all init arguments.", type: "array", }, // Maintainer options @@ -24,7 +31,7 @@ export function main(originalArgs: readonly string[]): void { type: "boolean", }, }) - .group(["init", "help", "version"], "User options") + .group(["init", "code", "help", "version"], "User options") .group(["debug", "selftest"], "Maintainer options") .parse(originalArgs); @@ -155,9 +162,21 @@ export function main(originalArgs: readonly string[]): void { } if (args.init) { - for (const path of args.init.map((arg) => arg.toString())) { - if (args.debug) console.info(`Adding file: '${path}' ...`); - init += fs.readFileSync(path, "utf8") + "\n"; + for (const source of args.init.map((arg) => arg.toString())) { + if (args.debug) console.info(`Adding code from: '${source}' ...`); + if (source.startsWith("https://")) { + const response = await axios.get(source); + init += response.data + "\n"; + } else { + init += fs.readFileSync(source, "utf8") + "\n"; + } + } + } + + if (args.code) { + for (const code of args.code.map((arg) => arg.toString())) { + if (args.debug) console.info(`Adding code: '${code}' ...`); + init += `${code}\n`; } }