Пример #1
0
int main (int argc, char* argv[]) {
  TRIAGENS_C_INITIALISE(argc, argv);
  TRI_InitialiseLogging(false);
  int ret = EXIT_SUCCESS;

  // .............................................................................
  // use relative system paths
  // .............................................................................

  {
    char* binaryPath = TRI_LocateBinaryPath(argv[0]);

#ifdef TRI_ENABLE_RELATIVE_SYSTEM
  
    StartupModules = string(binaryPath) + "/../share/arango/rb/client/modules"
             + ";" + string(binaryPath) + "/../share/arango/rb/common/modules";

#else

  // .............................................................................
  // use relative development paths
  // .............................................................................

#ifdef TRI_ENABLE_RELATIVE_DEVEL

#ifdef TRI_STARTUP_MODULES_PATH
    StartupModules = TRI_STARTUP_MODULES_PATH;
#else
    StartupModules = string(binaryPath) + "/rb/client/modules"
             + ";" + string(binaryPath) + "/rb/common/modules";
#endif

#else

  // .............................................................................
  // use absolute paths
  // .............................................................................

#ifdef _PKGDATADIR_

    StartupModules = string(_PKGDATADIR_) + "/rb/client/modules"
             + ";" + string(_PKGDATADIR_) + "/rb/common/modules";

#endif

#endif
#endif

    TRI_FreeString(TRI_CORE_MEM_ZONE, binaryPath);
  }

  // .............................................................................
  // parse the program options
  // .............................................................................

  ParseProgramOptions(argc, argv);

  // check connection args
  if (ConnectTimeout <= 0) {
    cout << "invalid value for connect-timeout." << endl;
    exit(EXIT_FAILURE);
  }

  if (RequestTimeout <= 0) {
    cout << "invalid value for request-timeout." << endl;
    exit(EXIT_FAILURE);
  }

  // .............................................................................
  // set-up MRuby objects
  // .............................................................................

  // create a new ruby shell
  mrb_state* mrb = MR_OpenShell();

  TRI_InitMRUtils(mrb);

  // .............................................................................
  // set-up client connection
  // .............................................................................

  // check if we want to connect to a server
  bool useServer = (ServerAddressPort != "none");

  if (useServer) {
    AddressPort ap;

    if (! ap.split(ServerAddressPort)) {
      if (! ServerAddress.empty()) {
        printf("Could not split %s.\n", ServerAddress.c_str());
        exit(EXIT_FAILURE);
      }
    }

    if (! ap._address.empty()) {
      ServerAddress = ap._address;
    }

    ServerPort = ap._port;
    
    ClientConnection = new MRubyClientConnection(
      mrb,
      ServerAddress, 
      ServerPort, 
      (double) RequestTimeout,
      DEFAULT_RETRIES, 
      (double) ConnectTimeout,
      false);

    InitMRClientConnection(mrb, ClientConnection);
  }
  
  // .............................................................................
  // banner
  // .............................................................................  

  // http://www.network-science.de/ascii/   Font: ogre
  if (! Quite) {
    char const* g = DEF_GREEN;
    char const* r = DEF_RED;
    char const* z = DEF_RESET;

    if (NoColors) {
      g = "";
      r = "";
      z = "";
    }

    printf("%s                                  %s _      _     %s\n", g, r, z);
    printf("%s  __ _ _ __ __ _ _ __   __ _  ___ %s(_)_ __| |__  %s\n", g, r, z);
    printf("%s / _` | '__/ _` | '_ \\ / _` |/ _ \\%s| | '__| '_ \\ %s\n", g, r, z);
    printf("%s| (_| | | | (_| | | | | (_| | (_) %s| | |  | |_) |%s\n", g, r, z);
    printf("%s \\__,_|_|  \\__,_|_| |_|\\__, |\\___/%s|_|_|  |_.__/ %s\n", g, r, z);
    printf("%s                       |___/      %s              %s\n", g, r, z);

    printf("\n");
    printf("Welcome to arangoirb %s. Copyright (c) 2012 triAGENS GmbH.\n", TRIAGENS_VERSION);

#ifdef TRI_V8_VERSION
    printf("Using MRUBY %s engine. Copyright (c) 2012 mruby developers.\n", TRI_MRUBY_VERSION);
#endif

#ifdef TRI_READLINE_VERSION
    printf("Using READLINE %s.\n", TRI_READLINE_VERSION);
#endif

    printf("\n");

    if (UsePager) {
      printf("Using pager '%s' for output buffering.\n", OutputPager.c_str());    
    }
 
    if (PrettyPrint) {
      printf("Pretty print values.\n");    
    }

    if (useServer) {
      if (ClientConnection->isConnected()) {
        if (! Quite) {
          printf("Connected to Arango DB %s:%d Version %s\n", 
                 ClientConnection->getHostname().c_str(), 
                 ClientConnection->getPort(), 
                 ClientConnection->getVersion().c_str());
        }
      }
      else {
        printf("Could not connect to server %s:%d\n", ServerAddress.c_str(), ServerPort);
        printf("Error message '%s'\n", ClientConnection->getErrorMessage().c_str());
      }
    }
  }

  // .............................................................................
  // read files
  // .............................................................................

  // load java script from js/bootstrap/*.h files
  if (StartupPath.empty()) {
    StartupLoader.defineScript("common/bootstrap/error.rb", MR_common_bootstrap_error);
  }
  else {
    LOGGER_DEBUG << "using JavaScript startup files at '" << StartupPath << "'";
    StartupLoader.setDirectory(StartupPath);
  }

  // load all init files
  char const* files[] = {
    "common/bootstrap/error.rb"
  };
  
  for (size_t i = 0;  i < sizeof(files) / sizeof(files[0]);  ++i) {
    bool ok = StartupLoader.loadScript(mrb, files[i]);
    
    if (ok) {
      LOGGER_TRACE << "loaded ruby file '" << files[i] << "'";
    }
    else {
      LOGGER_ERROR << "cannot load ruby file '" << files[i] << "'";
      exit(EXIT_FAILURE);
    }
  }
  
  // .............................................................................
  // run normal shell
  // .............................................................................

  RunShell(mrb);

  return ret;
}
Пример #2
0
int main (int argc, char* argv[]) {
  TRIAGENS_C_INITIALISE(argc, argv);
  TRIAGENS_REST_INITIALISE(argc, argv);

  TRI_InitialiseLogging(false);
  int ret = EXIT_SUCCESS;

  BaseClient.setEndpointString(Endpoint::getDefaultEndpoint());

  // .............................................................................
  // parse the program options
  // .............................................................................

  ParseProgramOptions(argc, argv);

  // .............................................................................
  // set-up MRuby objects
  // .............................................................................

  // create a new ruby shell
  mrb_state* mrb = MR_OpenShell();

  TRI_InitMRUtils(mrb);

  // .............................................................................
  // set-up client connection
  // .............................................................................

  // check if we want to connect to a server
  bool useServer = (BaseClient.endpointString() != "none");

  if (useServer) {
    BaseClient.createEndpoint();

    if (BaseClient.endpointServer() == 0) {
      LOGGER_FATAL_AND_EXIT("invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')");
    }

    ClientConnection = createConnection(mrb);
    InitMRClientConnection(mrb, ClientConnection);
  }

  // .............................................................................
  // banner
  // .............................................................................

  // http://www.network-science.de/ascii/   Font: ogre
  if (! BaseClient.quiet()) {
    char const* g = TRI_SHELL_COLOR_GREEN;
    char const* r = TRI_SHELL_COLOR_RED;
    char const* z = TRI_SHELL_COLOR_RESET;

    if (! BaseClient.colors()) {
      g = "";
      r = "";
      z = "";
    }

    printf("%s                                  %s _      _     %s\n", g, r, z);
    printf("%s  __ _ _ __ __ _ _ __   __ _  ___ %s(_)_ __| |__  %s\n", g, r, z);
    printf("%s / _` | '__/ _` | '_ \\ / _` |/ _ \\%s| | '__| '_ \\ %s\n", g, r, z);
    printf("%s| (_| | | | (_| | | | | (_| | (_) %s| | |  | |_) |%s\n", g, r, z);
    printf("%s \\__,_|_|  \\__,_|_| |_|\\__, |\\___/%s|_|_|  |_.__/ %s\n", g, r, z);
    printf("%s                       |___/      %s              %s\n", g, r, z);

    cout << endl << "Welcome to arangosh " << TRI_VERSION_FULL << ". Copyright (c) 2012 triAGENS GmbH" << endl;

#ifdef TRI_MRUBY_VERSION
    cout << "Using MRUBY " << TRI_MRUBY_VERSION << " engine. Copyright (c) 2012 mruby developers." << endl;
#endif

#ifdef TRI_READLINE_VERSION
    cout << "Using READLINE " << TRI_READLINE_VERSION << endl;
#endif

    cout << endl;

    BaseClient.printWelcomeInfo();

    if (useServer) {
      if (ClientConnection->isConnected()) {
        if (! BaseClient.quiet()) {
          cout << "Connected to ArangoDB '" << BaseClient.endpointServer()->getSpecification()
               << "' Version " << ClientConnection->getVersion() << endl;
        }
      }
      else {
        cerr << "Could not connect to endpoint '" << BaseClient.endpointString() << "'" << endl;
        cerr << "Error message '" << ClientConnection->getErrorMessage() << "'" << endl;
      }
    }
  }

  // .............................................................................
  // read files
  // .............................................................................

  // load java script from js/bootstrap/*.h files
  if (StartupPath.empty()) {
    StartupLoader.defineScript("common/bootstrap/error.rb", MR_common_bootstrap_error);
  }
  else {
    LOGGER_DEBUG("using Ruby startup files at '" << StartupPath << "'");
    StartupLoader.setDirectory(StartupPath);
  }

  // load all init files
  char const* files[] = {
    "common/bootstrap/error.rb"
  };

  for (size_t i = 0;  i < sizeof(files) / sizeof(files[0]);  ++i) {
    bool ok = StartupLoader.loadScript(mrb, files[i]);

    if (ok) {
      LOGGER_TRACE("loaded ruby file '" << files[i] << "'");
    }
    else {
      LOGGER_FATAL_AND_EXIT("cannot load ruby file '" << files[i] << "'");
    }
  }

  // .............................................................................
  // run normal shell
  // .............................................................................

  RunShell(mrb);

  TRIAGENS_REST_SHUTDOWN;

  return ret;
}