Skip to content

Commit

Permalink
Add aliases for arguments, don’t use snake_case for internal names
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Apr 22, 2019
1 parent 74ff79b commit 1e76806
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
21 changes: 14 additions & 7 deletions bin/near
Expand Up @@ -16,17 +16,17 @@ const deploy = {
command: 'deploy',
desc: 'deploy your smart contract',
builder: (yargs) => yargs
.option('node_url', {
.option('nodeUrl', {
desc: 'Near node url',
type: 'string',
default: 'http://localhost:3030'
})
.option('wasm_file', {
.option('wasmFile', {
desc: 'Path to wasm file to deploy',
type: 'string',
default: './out/main.wasm'
})
.option('account_id', {
.option('accountId', {
desc: 'Your developer account id. If you have only one account, that one will be selected by default',
type: 'string',
}),
Expand Down Expand Up @@ -55,12 +55,12 @@ const createAccount = {
command: 'create_account',
desc: 'create a developer account',
builder: (yargs) => yargs
.option('node_url', {
.option('nodeUrl', {
desc: 'Near node url',
type: 'string',
default: 'http://localhost:3030'
})
.option('account_id', {
.option('accountId', {
desc: 'Unique identifier for the new account',
type: 'string',
required: true
Expand All @@ -72,7 +72,7 @@ const clean = {
command: 'clean',
desc: 'clean the build environment',
builder: (yargs) => yargs
.option('out_dir', {
.option('outDir', {
desc: 'build directory',
type: 'string',
default: './out'
Expand All @@ -84,7 +84,7 @@ const newProject = {
command: 'new_project',
desc: 'create a new blank project',
builder: (yargs) => yargs
.option('project_dir', {
.option('projectDir', {
desc: 'project directory',
type: 'string',
default: '.'
Expand All @@ -98,6 +98,13 @@ yargs // eslint-disable-line
.command(deploy)
.command(clean)
.command(newProject)
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
'nodeUrl': 'node_url',
'wasmFile': 'wasm_file',
'projectDir': 'project_dir',
'outDir': 'out_dir'
})
.showHelpOnFail(true)
.demandCommand(1, 'Please enter a command')
.strict()
Expand Down
24 changes: 12 additions & 12 deletions index.js
Expand Up @@ -12,12 +12,12 @@ ncp.limit = 16;

exports.newProject = async function() {
// Need to wait for the copy to finish, otherwise next tasks do not find files.
const proj_dir = yargs.argv.project_dir;
const source_dir = __dirname + "/blank_project";
console.log(`Copying files to new project directory (${proj_dir}) from template source (${source_dir}).`);
const projectDir = yargs.argv.projectDir;
const sourceDir = __dirname + "/blank_project";
console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceDir}).`);
const copyDirFn = () => {
return new Promise(resolve => {
ncp (source_dir, yargs.argv.project_dir, response => resolve(response));
ncp (sourceDir, yargs.argv.projectDir, response => resolve(response));
})};
await copyDirFn();
console.log('Copying project files complete.')
Expand All @@ -26,7 +26,7 @@ exports.newProject = async function() {
exports.clean = async function() {
const rmDirFn = () => {
return new Promise(resolve => {
rimraf(yargs.argv.out_dir, response => resolve(response));
rimraf(yargs.argv.outDir, response => resolve(response));
})};
await rmDirFn();
console.log("Clean complete.");
Expand All @@ -35,8 +35,8 @@ exports.clean = async function() {
// Only works for dev environments
exports.createDevAccount = async function(argv) {
const keyPair = await KeyPair.fromRandomSeed();
const accountId = argv.account_id;
const nodeUrl = argv.node_url;
const accountId = argv.accountId;
const nodeUrl = argv.nodeUrl;

const options = {
nodeUrl,
Expand All @@ -62,7 +62,7 @@ async function deployContractAndWaitForTransaction(accountId, data, near) {

exports.deploy = async function(argv) {
const keyStore = new UnencryptedFileSystemKeyStore();
let accountId = argv.account_id;
let accountId = argv.accountId;
if (!accountId) {
// see if we only have one account in keystore and just use that.
const accountIds = await keyStore.getAccountIds();
Expand All @@ -71,9 +71,9 @@ exports.deploy = async function(argv) {
}
}
if (!accountId) {
throw 'Please provide account id and make sure you created an account using near create_account';
throw new Error('Please provide account id and make sure you created an account using near create_account');
}
const nodeUrl = argv.node_url;
const nodeUrl = argv.nodeUrl;
const options = {
nodeUrl,
accountId,
Expand All @@ -84,10 +84,10 @@ exports.deploy = async function(argv) {
};

const near = await neardev.connect(options);
const contractData = [...fs.readFileSync(argv.wasm_file)];
const contractData = [...fs.readFileSync(argv.wasmFile)];

console.log(
"Starting deployment. Account id " + accountId + ", contract " + accountId + ", url " + nodeUrl, ", file " + argv.wasm_file);
"Starting deployment. Account id " + accountId + ", contract " + accountId + ", url " + nodeUrl, ", file " + argv.wasmFile);
const res = await deployContractAndWaitForTransaction(
accountId, contractData, near);
if (res.status == "Completed") {
Expand Down

0 comments on commit 1e76806

Please sign in to comment.