Ejemplo n.º 1
0
int pmdOptions::init(int argc, char **argv)
{
	int rc = EDB_OK;
	
	po::options_description all("Command options");
	po::variables_map vm;
	po::variables_map vm2;
	
	PMD_ADD_PARAM_OPTIONS_BEGIN(all)
		PMD_COMMANDS_OPTIONS
	PMD_ADD_PARAM_OPTIONS_END
	
	rc = readCmd(ragc, argv, all, vm);
	if(rc)
	{
		PD_LOG(PDERROR, "Failed to read cmd, rc=%d", rc);
		goto error;
	}
	
	//check if we have help options
	if(vm.count(PMD_OPTION_HELP))
	{
		std::cout<<all<<std::endl;
		
		rc = EDB__PMD_HELP_ONLY;
		goto done;
	}
	
	//check if there's conf path
	if(vm.count(PMD_OPTION_CONFPATH))
	{
		rc = readConfigureFile(vm[PMD_OPTION_CONFPATH].as<string>().c_str(), all, vm2);
	}
	if(rc)
	{
		PD_LOG(PDERROR, "Unexpected error when reading conf file, rc = %d", rc);
		goto error;
	}
	
	//load vm from file
	rc = importVM(vm2);
	if(rc)
	{
		PD_LOG(PDERROR, "Failed to import from vm2, rc = %d", rc);
		goto error;
	}
	
	//load vm from command line
	rc = importVM(vm);
	if(rc)
	{
		PD_LOG(PDERROR, "Failed to import from vm, rc = %d", rc);
		goto error;
	}

done:
	return rc;
error:
	goto done;
}
Ejemplo n.º 2
0
   // initialize options
   INT32 initArgs ( INT32 argc, CHAR **argv, po::variables_map &vm )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ( "Command options" ) ;
      po::options_description all ( "Command options" ) ;

      PMD_ADD_PARAM_OPTIONS_BEGIN ( all )
         COMMANDS_OPTIONS
         COMMANDS_HIDE_OPTIONS
      PMD_ADD_PARAM_OPTIONS_END

      PMD_ADD_PARAM_OPTIONS_BEGIN ( desc )
         COMMANDS_OPTIONS
      PMD_ADD_PARAM_OPTIONS_END

      // validate arguments
      rc = utilReadCommandLine( argc, argv, all, vm ) ;
      if ( rc )
      {
         std::cout << "Invalid arguments: " << rc << std::endl ;
         displayArg ( desc ) ;
         goto done ;
      }

      /// read cmd first
      if ( vm.count( PMD_OPTION_HELP ) )
      {
         displayArg( desc ) ;
         rc = SDB_PMD_HELP_ONLY ;
         goto done ;
      }
      if ( vm.count( PMD_OPTION_HELPFULL ) )
      {
         displayArg( all ) ;
         rc = SDB_PMD_HELP_ONLY ;
         goto done ;
      }
      if ( vm.count( PMD_OPTION_VERSION ) )
      {
         ossPrintVersion( "Sdb CM version" ) ;
         rc = SDB_PMD_VERSION_ONLY ;
         goto done ;
      }

   done:
      return rc ;
   }
Ejemplo n.º 3
0
   INT32 utilGetInstallInfo( utilInstallInfo & info )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ;
      po::variables_map vm ;

      PMD_ADD_PARAM_OPTIONS_BEGIN( desc )
         ( SDB_INSTALL_RUN_FILED, po::value<string>(), "after to run cmd" ) \
         ( SDB_INSTALL_USER_FIELD, po::value<string>(), "user" ) \
         ( SDB_INSTALL_PATH_FIELD, po::value<string>(), "install path" )
      PMD_ADD_PARAM_OPTIONS_END

      rc = ossAccess( SDB_INSTALL_FILE_NAME ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Access file[%s] failed, rc: %d",
                 SDB_INSTALL_FILE_NAME, rc ) ;
         goto error ;
      }

      rc = utilReadConfigureFile( SDB_INSTALL_FILE_NAME, desc, vm ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Failed to read install info from file, rc: %d",
                 rc ) ;
         goto error ;
      }

      if ( vm.count( SDB_INSTALL_RUN_FILED ) )
      {
         info._run = vm[ SDB_INSTALL_RUN_FILED ].as<string>() ;
      }
      if ( vm.count( SDB_INSTALL_USER_FIELD ) )
      {
         info._user = vm[ SDB_INSTALL_USER_FIELD ].as<string>() ;
      }
      if ( vm.count( SDB_INSTALL_PATH_FIELD ) )
      {
         info._path = vm[ SDB_INSTALL_PATH_FIELD ].as<string>() ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Ejemplo n.º 4
0
   INT32 initArgs ( INT32 argc, CHAR **argv, po::variables_map &vm,
                    BOOLEAN &asProc )
   {
      INT32 rc = SDB_OK ;
      po::options_description desc ( "Command options" ) ;

      PMD_ADD_PARAM_OPTIONS_BEGIN ( desc )
         COMMANDS_OPTIONS
      PMD_ADD_PARAM_OPTIONS_END

      rc = utilReadCommandLine( argc, argv, desc, vm ) ;
      if ( rc )
      {
         std::cout << "Invalid arguments: " << rc << std::endl ;
         displayArg ( desc ) ;
         goto done ;
      }

      if ( vm.count( PMD_OPTION_HELP ) )
      {
         displayArg( desc ) ;
         rc = SDB_PMD_HELP_ONLY ;
         goto done ;
      }
      if ( vm.count( PMD_OPTION_VERSION ) )
      {
         ossPrintVersion( "Sdb CMD version" ) ;
         rc = SDB_PMD_VERSION_ONLY ;
         goto done ;
      }
#if defined( _WINDOWS )
      if ( vm.count( PMD_OPTION_AS_PROC ) )
      {
         asProc = TRUE ;
      }
#endif //_WINDOWS

   done:
      return rc ;
   }