Skip to content

Commit

Permalink
Added CLI support for stand-alone (no sub-command) tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 27, 2019
1 parent 74dbc28 commit b67b121
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 78 deletions.
39 changes: 35 additions & 4 deletions packages/cli/src.ts/bin/ethers-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { join as pathJoin } from "path";

import { ethers } from 'ethers';

import { ArgParser, CLI, Plugin } from '../cli';
import { ArgParser, CLI, Help, Plugin } from '../cli';
import { header as Header, generate as generateTypeScript } from "../typescript";
import { compile, ContractCode } from "../solc";

Expand Down Expand Up @@ -50,7 +50,11 @@ function walkFilenames(filenames: Array<string>): Array<string> {
return result;
}

let cli = new CLI("generate");
let cli = new CLI(null, {
account: false,
provider: false,
transaction: false
});

class GeneratePlugin extends Plugin {

Expand All @@ -60,12 +64,39 @@ class GeneratePlugin extends Plugin {
optimize: boolean;
noBytecode: boolean;

static getHelp(): Help {
return {
name: "FILENAME [ ... ]",
help: "Generates a TypeScript file of all Contracts. May specify folders."
};
}
static getOptionHelp(): Array<Help> {
return [
{
name: "--output FILENAME",
help: "Write the output to FILENAME (default: stdout)"
},
{
name: "--force",
help: "Overwrite files if they already exist"
},
{
name: "--no-optimize",
help: "Do not run the solc optimizer"
},
{
name: "--no-bytecode",
help: "Do not include bytecode and Factory methods"
}
];
}

async prepareOptions(argParser: ArgParser): Promise<void> {
await super.prepareOptions(argParser);

this.output = argParser.consumeOption("output");
this.force = argParser.consumeFlag("force");
this.optimize = argParser.consumeFlag("no-optimize");
this.optimize = !argParser.consumeFlag("no-optimize");
this.noBytecode = argParser.consumeFlag("no-bytecode");
}

Expand Down Expand Up @@ -121,6 +152,6 @@ class GeneratePlugin extends Plugin {
return Promise.resolve(null);
}
}
cli.addPlugin("generate", GeneratePlugin);
cli.setPlugin(GeneratePlugin);

cli.run(process.argv.slice(2))
Loading

0 comments on commit b67b121

Please sign in to comment.