Boost logo

Boost Users :

Subject: Re: [Boost-users] Program Options.. Specifying "-e" as an optionvalue.....
From: david.weber_at_[hidden]
Date: 2010-10-08 11:30:09


Well. Here's the rub: That's not the requested behavior...

I want behavior, where I specify an argument which follows the following pattern:

-a <some text string>


pseudo-code:

for(int i = 0; i < argc; i++)
{
        if argv[i] == "-a"
        {
                i++;
                if(i < argc)
                {
                           arg_vector.push_back(argv[i]);
                }
                else {} // error
          }
}


Instead, it processes each argument individually, attempting to match each argv value with an "argument pattern" (in the style of the following regular expressions which probably don't work, but you should hopefully get the idea: -[a-zA-Z] or --[a-zA-Z]+ )

If they match the regular expression, the are sent to some sort of handler which determines what to do with them. Below is a pseudo-code of how it appears to currently work, and a workaround. I think I just may have hit a special case...


for(int i = 0; i < argc; i++)
{
        if isArgument(argv[i])
        {
                if(handleArgument(argv[i]))
                {
                        // success
                        continue;
                }
/**
                // This following case should be added
                else if(isEscaped(argv[i]) && argumentHasParameter(argv[i-1]))
                {
                        handleArgumentParameter(argv[i-1], argv[i]);
                        continue;
                }
**/
                else
                {
                        // failure
                }
        }
        else if(argumentHasParameter(argv[i-1]))
        {
                handleArgumentParameter(argv[i-1], argv[i]);
                continue;
          }
}


I'll be poking around in the code to see what it looks like presently...



-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Diederick C. Niehorster
Sent: Thursday, October 07, 2010 8:17 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Program Options.. Specifying "-e" as an optionvalue.....

I don't know too much about the library, but see that i your code you
use a capital E. See if there is a way to turn on
case-insensitiveness, or change it to what you want it to be.

Best,
Dee

On Fri, Oct 8, 2010 at 06:19, <david.weber_at_[hidden]> wrote:
> I have an application, which spawns off other applications.  As input, it
> takes in environment variables and arguments to pass to the resultant
> application.  For instance:
>
>
>
>
>
> mutate -E “env_var1=val” -a “.” ls
>
>
>
> This will run:
>
>
>
> ls .
>
>
>
> and the environment will only have “env_var1” equal to “val”
>
>
>
>
>
> So.  Something funny comes along when I try to pass “-e” as an argument.
>
>
>
> So, in the above would be:
>
>
>
> mutate -a “-e” –a “foo” xterm
>
>
>
> The program options parser attempts to parse the “-e”, and says “I don’t
> know what it is”.
>
>
>
> Any thoughts on having it skip that option?
>
>
>
>
>
> Code Snippits:
>
>
>
>
>
>     po::options_description visible("Program options. Usage %1%");
>
>     visible.add_options()
>
>         ("env,E", po::value<string_vector_t>(), "Specify an environment
> variable to run the executable with. In the form of foo=bar")
>
>         ("arg,a", po::value<string_vector_t>(), "Specify a command line
> argument to pass to the executable")
>
>     ;
>
>
>
>     // Set up some hidden options
>
>     po::options_description hidden("Hidden options");
>
>     hidden.add_options()
>
>         ("executable", po::value < std::string>(), "the executable to run")
>
>     ;
>
>
>
>     // Set up positional arguments.  They are going to be execute
>
>     po::positional_options_description pos;
>
>     pos.add("executable", 1);      // There can only be 1 item executed
>
>
>
>     // Consolidate all the options into a single one
>
>     po::options_description all_options("All Options");
>
>     all_options.add(visible);
>
>     all_options.add(hidden);
>
>
>
>     // Parse the command line options
>
>     po::store(po::command_line_parser(argc,
> argv).options(all_options).positional(pos).run(), vm);
>
>     po::notify(vm);
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net