@@ -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.' ; 
@@ -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,6 +143,9 @@ 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 )  { 
147+       this . error ( '--network is required when using --from-contract or --spkg' ) ; 
148+     } 
146149
147150    const  {  node }  =  chooseNodeUrl ( { 
148151      node : nodeFlag , 
@@ -200,7 +203,7 @@ export default class InitCommand extends Command {
200203
201204    // If all parameters are provided from the command-line, 
202205    // go straight to creating the subgraph from an existing contract 
203-     if  ( fromContract  &&  protocol  &&  subgraphName  &&  directory  &&  network  &&  node )  { 
206+     if  ( ( fromContract   ||   spkgPath )  &&  protocol  &&  subgraphName  &&  directory  &&  network  &&  node )  { 
204207      const  registry  =  await  loadRegistry ( ) ; 
205208      const  contractService  =  new  ContractService ( registry ) ; 
206209
@@ -225,7 +228,7 @@ export default class InitCommand extends Command {
225228          } 
226229        }  else  { 
227230          try  { 
228-             abi  =  await  contractService . getABI ( ABI ,  network ,  fromContract ) ; 
231+             abi  =  await  contractService . getABI ( ABI ,  network ,  fromContract ! ) ; 
229232          }  catch  ( e )  { 
230233            this . exit ( 1 ) ; 
231234          } 
@@ -237,11 +240,11 @@ export default class InitCommand extends Command {
237240          protocolInstance, 
238241          abi, 
239242          directory, 
240-           source : fromContract , 
243+           source : fromContract ! , 
241244          indexEvents, 
242245          network, 
243246          subgraphName, 
244-           contractName, 
247+           contractName :  contractName   ||   DEFAULT_CONTRACT_NAME , 
245248          node, 
246249          startBlock, 
247250          spkgPath, 
@@ -303,7 +306,7 @@ export default class InitCommand extends Command {
303306          network : answers . network , 
304307          source : answers . source , 
305308          indexEvents : answers . indexEvents , 
306-           contractName : answers . contractName , 
309+           contractName : answers . contractName   ||   DEFAULT_CONTRACT_NAME , 
307310          node, 
308311          startBlock : answers . startBlock , 
309312          spkgPath : answers . spkgPath , 
0 commit comments