function ApiCommander(apis) {
  return {
    end: true,
    apis: apis,
    commands: {},
    add: function(command) {
      this.commands[command.name] = command;
    },
    run: async function(options) {
      while (this.end) {
        const prompt = '>> ';
        const line = await getSTDInput(prompt);
        const args = stringArgv(line);

        if (args.length === 0) {
          continue;
        }

        // check default command
        switch (args[0]) {
          case 'help':
            let msg = 'Usage: <command> [<args...>]\n\n';
            msg = msg + 'where <command> is one of: call, show, list, help\n\n';
            msg = msg + 'Commands:\n\n';
            for (const key of Object.keys(this.commands)) {
              const command = this.commands[key];
              msg =
                msg +
                '\t{0} {1}{2}\n\n'.format(
                  chalk.bold(command.name.padEnd(8)),
                  chalk.bold(command.options.padEnd(60)),
                  command.description
                );
            }
            console.log(msg);
            continue;
          case 'exit':
            this.end = false;
            continue;
        }

        if (this.commands[args[0]] === undefined) {
          console.log('invalid command: {0}'.format(args[0]));
          continue;
        }

        // run command
        try {
          await this.commands[args[0]].run(
            args.slice(1, args.length),
            this.apis,
            options
          );
        } catch (e) {
          console.log(e);
        }
      }
    }
  };
}
/**
 *
 * @param {object} apis has an api of smart contracts
 */
@param {object} apis has an api of smart contracts
@param { object } apis has an api of smart contracts
function ApiCommander(apis) {
  return {
    end: true,
    apis: apis,
    commands: {},
    add: function(command) {
      this.commands[command.name] = command;
    },
    run: async function(options) {
      while (this.end) {
        const prompt = '>> ';
        const line = await getSTDInput(prompt);
        const args = stringArgv(line);
        if (args.length === 0) {
          continue;
        }
        switch (args[0]) {
          case 'help':
            let msg = 'Usage: <command> [<args...>]\n\n';
            msg = msg + 'where <command> is one of: call, show, list, help\n\n';
            msg = msg + 'Commands:\n\n';
            for (const key of Object.keys(this.commands)) {
              const command = this.commands[key];
              msg =
                msg +
                '\t{0} {1}{2}\n\n'.format(
                  chalk.bold(command.name.padEnd(8)),
                  chalk.bold(command.options.padEnd(60)),
                  command.description
                );
            }
            console.log(msg);
            continue;
          case 'exit':
            this.end = false;
            continue;
        }
        if (this.commands[args[0]] === undefined) {
          console.log('invalid command: {0}'.format(args[0]));
          continue;
        }
        try {
          await this.commands[args[0]].run(
            args.slice(1, args.length),
            this.apis,
            options
          );
        } catch (e) {
          console.log(e);
        }
      }
    }
  };
}
function ApiCommander ( apis ) { return { end : true , apis : apis , commands : { } , add : function ( command ) { this . commands [ command . name ] = command ; } , run : async function ( options ) { while ( this . end ) { const prompt = '>> ' ; const line = await getSTDInput ( prompt ) ; const args = stringArgv ( line ) ; if ( args . length === 0 ) { continue ; } switch ( args [ 0 ] ) { case 'help' : let msg = 'Usage: <command> [<args...>]\n\n' ; msg = msg + 'where <command> is one of: call, show, list, help\n\n' ; msg = msg + 'Commands:\n\n' ; for ( const key of Object . keys ( this . commands ) ) { const command = this . commands [ key ] ; msg = msg + '\t{0} {1}{2}\n\n' . format ( chalk . bold ( command . name . padEnd ( 8 ) ) , chalk . bold ( command . options . padEnd ( 60 ) ) , command . description ) ; } console . log ( msg ) ; continue ; case 'exit' : this . end = false ; continue ; } if ( this . commands [ args [ 0 ] ] === undefined ) { console . log ( 'invalid command: {0}' . format ( args [ 0 ] ) ) ; continue ; } try { await this . commands [ args [ 0 ] ] . run ( args . slice ( 1 , args . length ) , this . apis , options ) ; } catch ( e ) { console . log ( e ) ; } } } } ; }
@param {object} apis has an api of smart contracts
@param { object } apis has an api of smart contracts
// check default command // run command