Beispiel #1
0
int main(int argc, char **argv)
{
    int c;
    // sFlag is TRUE if script is set, otherwise FALSE.
    // This means that interactive mode is the default.
    // NOTE: getopt requires flags to have static storage duration.
    static int sFlag = FALSE;
    while (1) {
	static struct option long_options[] = {
	    {"interactive", no_argument, &sFlag, 0},
	    {"script", no_argument, &sFlag, 1},
	    {"help", no_argument, 0, 'h'},
	    {0, 0, 0, 0}
	};
	int option_index = 0; // holds the index of the long option found
	c = getopt_long(argc, argv, "h", long_options, &option_index);
	if (c == -1) {
	    break;
	}
	switch (c) {
	case 0:
	    // Return value is 0 if getopt_long encounts a flag
	    break;
	case 'h':
	    printHelpMsg();
	    return 0;
	default:
	    printf("Unrecognized option\n");
	    printHelpMsg();
	    exit(1);
	}
    }
    if (sFlag) {
	runScript();
    } else {
	runInteractive();
    }
    return 0; 
}
Beispiel #2
0
int main(int argc, char** argv)
{

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments fromt he command
    // line.

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments fromt he command
    // line.

    OptionManager om;

    try
    {
         String testHome = ".";
                 GetOptions(om, argc, argv, testHome);
         // om.print();
    }
    catch (Exception& e)
    {
         cerr << argv[0] << ": " << e.getMessage() << endl;
         exit(1);
    }


    // Check to see if user asked for help (-h otpion):
    if (om.valueEquals("verbose", "true"))
    {
                printHelpMsg(argv[0], usage, extra, om);
        exit(0);
    }

    // Establish the namespace from the input parameters
    String nameSpace;
    if(om.lookupValue("namespace", nameSpace))
    {
       cout << "Namespace = " << nameSpace << endl;

    }

    Boolean verboseTest = (om.valueEquals("verbose", "true")) ? true :false;
    /*
    Boolean activeTest = false;
    if (om.valueEquals("active", "true"))
         activeTest = true;
    */
    // Now develop the target instname from the arglist
    // For this one, at least one arguement is required
    // Not sure if this is true.
    // Think we should be able to get by with no argument.
    if (om.valueEquals("help", "true"))
    {
        String header = "Usage ";
        String trailer = "";
        om.printOptionsHelpTxt(header, trailer);
        exit(0);
    }

    String location =   "localhost:5988";
    if(om.lookupValue("location", location))
    {
       cout << "Location = " << location << endl;

    }

    // here we assume class name = null if none specified.
    String className = "";
    if (argc > 1)
    {
    className = argv[1];
    }

    CIMClient client;

    try
    {
        client.connect(location, String::EMPTY, String::EMPTY);
    }

    catch(Exception &e)
    {
      cerr << "Internal Error:" << e.getMessage() << endl;
    }


    Array<CIMObjectPath> instanceNames =
        client.enumerateInstanceNames(nameSpace, className);
    try
    {

        //simply output the list one per line for the moment.
    for (Uint32 i = 0; i < instanceNames.size(); i++)
        cout << instanceNames[i] << endl;
    }
    catch(Exception& e)
    {
    PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
    exit(1);
    }

    PEGASUS_STD(cout) << "+++++ passed all tests" << PEGASUS_STD(endl);

    return 0;
}