@@ -32,6 +32,7 @@ const protocolChoices = Array.from(Protocol.availableProtocols().keys());
32
32
const initDebugger = debugFactory ( 'graph-cli:commands:init' ) ;
33
33
34
34
const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar' ;
35
+ const DEFAULT_CONTRACT_NAME = 'Contract' ;
35
36
36
37
export default class InitCommand extends Command {
37
38
static description = 'Creates a new subgraph with basic scaffolding.' ;
@@ -61,7 +62,7 @@ export default class InitCommand extends Command {
61
62
description : 'Creates a scaffold based on an example subgraph.' ,
62
63
// TODO: using a default sets the value and therefore requires not to have --from-contract
63
64
// default: 'Contract',
64
- exclusive : [ 'from-contract' ] ,
65
+ exclusive : [ 'from-contract' , 'spkg' ] ,
65
66
} ) ,
66
67
67
68
'contract-name' : Flags . string ( {
@@ -103,7 +104,6 @@ export default class InitCommand extends Command {
103
104
summary : 'Network the contract is deployed to.' ,
104
105
description :
105
106
'Refer to https://github.com/graphprotocol/networks-registry/ for supported networks' ,
106
- dependsOn : [ 'from-contract' ] ,
107
107
} ) ,
108
108
109
109
ipfs : Flags . string ( {
@@ -143,17 +143,14 @@ export default class InitCommand extends Command {
143
143
'The --skip-git flag will be removed in the next major version. By default we will stop initializing a Git repository.' ,
144
144
) ;
145
145
}
146
+ if ( ( ! fromContract || ! spkgPath ) && ! network && ! fromExample ) {
147
+ this . error ( '--network is required when using --from-contract or --spkg' ) ;
148
+ }
146
149
147
150
const { node } = chooseNodeUrl ( {
148
151
node : nodeFlag ,
149
152
} ) ;
150
153
151
- if ( fromContract && fromExample ) {
152
- this . error ( 'Only one of "--from-example" and "--from-contract" can be used at a time.' , {
153
- exit : 1 ,
154
- } ) ;
155
- }
156
-
157
154
// Detect git
158
155
const git = system . which ( 'git' ) ;
159
156
if ( ! git ) {
@@ -200,7 +197,7 @@ export default class InitCommand extends Command {
200
197
201
198
// If all parameters are provided from the command-line,
202
199
// go straight to creating the subgraph from an existing contract
203
- if ( fromContract && protocol && subgraphName && directory && network && node ) {
200
+ if ( ( fromContract || spkgPath ) && protocol && subgraphName && directory && network && node ) {
204
201
const registry = await loadRegistry ( ) ;
205
202
const contractService = new ContractService ( registry ) ;
206
203
@@ -225,7 +222,7 @@ export default class InitCommand extends Command {
225
222
}
226
223
} else {
227
224
try {
228
- abi = await contractService . getABI ( ABI , network , fromContract ) ;
225
+ abi = await contractService . getABI ( ABI , network , fromContract ! ) ;
229
226
} catch ( e ) {
230
227
this . exit ( 1 ) ;
231
228
}
@@ -237,11 +234,11 @@ export default class InitCommand extends Command {
237
234
protocolInstance,
238
235
abi,
239
236
directory,
240
- source : fromContract ,
237
+ source : fromContract ! ,
241
238
indexEvents,
242
239
network,
243
240
subgraphName,
244
- contractName,
241
+ contractName : contractName || DEFAULT_CONTRACT_NAME ,
245
242
node,
246
243
startBlock,
247
244
spkgPath,
@@ -303,7 +300,7 @@ export default class InitCommand extends Command {
303
300
network : answers . network ,
304
301
source : answers . source ,
305
302
indexEvents : answers . indexEvents ,
306
- contractName : answers . contractName ,
303
+ contractName : answers . contractName || DEFAULT_CONTRACT_NAME ,
307
304
node,
308
305
startBlock : answers . startBlock ,
309
306
spkgPath : answers . spkgPath ,
0 commit comments