-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·164 lines (155 loc) · 5.24 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env node
'use strict';
const merge = require('deepmerge');
const path = require('path');
const yargs = require('yargs');
const util = require('util');
const Runner = require('./');
const ScriptReader = require('./lib/script-reader');
const formatStateArgs = require('./lib/format-state-args');
const defaultWorkingDirectory = path.join(__dirname, '/../../');
yargs
.usage('$0 <path..>')
.command({
command: '$0 <path..>',
desc: 'Run the blockchain scripts defined by the list of files.',
builder: (yargs) => {
yargs.positional('path', {
describe: 'Glob path of scripts to run. This can be the output yaml from a previously failed run.',
type: 'string',
});
yargs.options({
workingDirectory: {
alias: 'd',
description: 'Location of truffle project.',
type: 'string',
coerce: arg => ScriptReader.coerceRelativePath(arg, __dirname),
default: defaultWorkingDirectory,
},
state: {
description: 'Values to pass to the state which may be referenced in scripts.',
alias: 'env',
type: 'string',
},
networkName: {
description: 'Network name to run transactions on. Should correspond to one defined in truffle.js',
alias: 'n',
type: 'string',
default: 'development',
},
results: {
description: 'Path to output result logs of transactions succeeded and failed. Failed tasks can be replayed later.',
alias: 'resultsDir',
type: 'string',
},
interactive: {
description: 'Whether to prompt to confirm each step.',
default: true,
type: 'boolean',
},
inputs: {
description: 'Path(s) to a file containing inputs and/or individual properties to set on the state.$inputs. Files will be loaded and parsed.',
alias: ['input', 'i'],
type: 'string',
},
deployed: {
description: 'Path(s) to a file containing addresses of deployed contracts and/or individual properties to set on the state.$deployed. Files will be loaded and parsed.',
alias: ['e'],
type: 'string',
},
debug: {
description: 'Log initial state, inputs, and outputs to console',
alias: ['verbose', 'v'],
type: 'boolean',
},
debugInspectDepth: {
description: 'How deep to print objects (util.inspect depth)',
type: 'number',
default: 5,
hidden: true,
},
delay: {
description: 'Delay between methods',
type: 'number',
default: 0,
hidden: true,
},
dump: {
description: 'Whether to dump state upon finish',
type: 'boolean',
default: false,
implies: ['dumpPath'],
},
dumpFilename: {
description: 'Where to dump the state upon finish',
type: 'string',
},
dumpPath: {
description: 'A list of paths that should be dumped.',
type: 'array',
default: ['$deployed'],
hidden: true,
},
contracts: {
description: 'Path to location of contract arficats (ABI) JSON files',
type: 'string',
hidden: true,
},
closeOnFinish: {
description: 'Whether to shut down provider connections and dangling event listeners upon finish.',
hidden: true,
type: 'boolean',
default: true,
},
mapping: {
description: 'Path to a definition of a map to be used by truffle-object-mapper for calls to util.map',
hidden: false,
type: 'string',
default: 'mapping.js',
},
spinner: {
description: 'Show progress information in the form of a spinner',
type: 'boolean',
default: true,
},
logger: {
description: 'If spinner is disabled, log output to conventional std and stderr streams',
type: 'boolean',
default: false,
},
});
},
handler: async (argv) => {
let runner;
try {
argv.scriptDirectory = __dirname;
runner = new Runner(argv);
const objectifyArgvProperty = formatStateArgs(runner.scriptReader);
// ensure relative paths of input files coerced into absolute
// using the workingDirectory
const $inputs = objectifyArgvProperty(argv.inputs, '$inputs');
const $deployed = merge($inputs.$deployed, objectifyArgvProperty(argv.deployed, '$deployed'));
delete $inputs.$deployed;
const state = {
$deployed,
$inputs,
};
if (argv.debug) {
const deserializedState = util.inspect(state, {
depth: argv.debugInspectDepth,
});
runner.spinner.info(`Initial state is: \n${deserializedState}`);
}
// run list of script files found at specified path(s)
await runner.read(argv.path, state);
} catch (err) {
/* eslint no-console: 0 */
console.error('Failed with error:', err);
console.error(err.stack);
}
},
})
.strict(true)
.demandCommand()
.help()
.argv;