@@ -32,6 +32,7 @@ const protocolChoices = Array.from(Protocol.availableProtocols().keys());
3232const initDebugger = debugFactory ( 'graph-cli:commands:init' ) ;
3333
3434const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar' ;
35+ const DEFAULT_CONTRACT_NAME = 'Contract' ;
3536
3637export default class InitCommand extends Command {
3738 static description = 'Creates a new subgraph with basic scaffolding.' ;
@@ -61,7 +62,7 @@ export default class InitCommand extends Command {
6162 description : 'Creates a scaffold based on an example subgraph.' ,
6263 // TODO: using a default sets the value and therefore requires not to have --from-contract
6364 // default: 'Contract',
64- exclusive : [ 'from-contract' ] ,
65+ exclusive : [ 'from-contract' , 'spkg' ] ,
6566 } ) ,
6667
6768 'contract-name' : Flags . string ( {
@@ -103,7 +104,6 @@ export default class InitCommand extends Command {
103104 summary : 'Network the contract is deployed to.' ,
104105 description :
105106 'Refer to https://github.com/graphprotocol/networks-registry/ for supported networks' ,
106- dependsOn : [ 'from-contract' ] ,
107107 } ) ,
108108
109109 ipfs : Flags . string ( {
@@ -143,17 +143,14 @@ export default class InitCommand extends Command {
143143 'The --skip-git flag will be removed in the next major version. By default we will stop initializing a Git repository.' ,
144144 ) ;
145145 }
146+ if ( ( ! fromContract || ! spkgPath ) && ! network && ! fromExample ) {
147+ this . error ( '--network is required when using --from-contract or --spkg' ) ;
148+ }
146149
147150 const { node } = chooseNodeUrl ( {
148151 node : nodeFlag ,
149152 } ) ;
150153
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-
157154 // Detect git
158155 const git = system . which ( 'git' ) ;
159156 if ( ! git ) {
@@ -200,7 +197,7 @@ export default class InitCommand extends Command {
200197
201198 // If all parameters are provided from the command-line,
202199 // 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 ) {
204201 const registry = await loadRegistry ( ) ;
205202 const contractService = new ContractService ( registry ) ;
206203
@@ -225,7 +222,7 @@ export default class InitCommand extends Command {
225222 }
226223 } else {
227224 try {
228- abi = await contractService . getABI ( ABI , network , fromContract ) ;
225+ abi = await contractService . getABI ( ABI , network , fromContract ! ) ;
229226 } catch ( e ) {
230227 this . exit ( 1 ) ;
231228 }
@@ -237,11 +234,11 @@ export default class InitCommand extends Command {
237234 protocolInstance,
238235 abi,
239236 directory,
240- source : fromContract ,
237+ source : fromContract ! ,
241238 indexEvents,
242239 network,
243240 subgraphName,
244- contractName,
241+ contractName : contractName || DEFAULT_CONTRACT_NAME ,
245242 node,
246243 startBlock,
247244 spkgPath,
@@ -303,7 +300,7 @@ export default class InitCommand extends Command {
303300 network : answers . network ,
304301 source : answers . source ,
305302 indexEvents : answers . indexEvents ,
306- contractName : answers . contractName ,
303+ contractName : answers . contractName || DEFAULT_CONTRACT_NAME ,
307304 node,
308305 startBlock : answers . startBlock ,
309306 spkgPath : answers . spkgPath ,
0 commit comments