//
// C++ OptParse - A very simple example
//

#include <cstdio>
#include "optparse.h"

int main(int argc, char** argv)
{
    //
    // Create an options object
    //
    Options o;
    
    //
    // ...and add two switches to it, each of them not being optional and needing an argument
    //
    o.addOption("-h","--host","Remote hostname", OPT_REQUIRED | OPT_NEEDARG);
    o.addOption("-p","--port","Remote port", OPT_REQUIRED | OPT_NEEDARG);
    
    //
    // Create a parser for the command line
    //
    Parser p;
    
    //
    // ...and use it on the program's arguments, along with the options object
    //
    int result = p.parse(argc, argv, o);
    
    //
    // Check the results of the parsing
    //
    if ( result == E_OK )
    {
        //
        // Pretend to invoke the telnet command. No validations are performed.
        //
        char buf[1024];
        
        snprintf(buf, sizeof(buf), "telnet %s %s", o.asString("-h").c_str(), o.asString("-p").c_str() );
        buf[sizeof(buf)-1] = 0;
        
        printf("\nRun: %s", buf);
    }
    else
    {
        printf("\nError parsing command line.");
    }
    
    printf("\n");
    
    return 0;
}