Hi sgp,
> I'm enjoying this thread! Thanks.
Good.
> > Right, so you want to get all your options into the first
> > powerpro argument. You don't want to parse _all_ the powerpro
args,
> > just the first one?
> >
> Actually, in my scriptlet example I was parsing all arguments, but
I
> concatenated them into a single string first. I can't think of
another
> simple ppro idiom to do that. Can you?
I think we leave that up to the plugin user. Plugin just receives
one string, assumes within that string the usual thing (white space
delimits args, commas don't matter). User either passes in
all args or one, depending on how he wants to use i.e. he may wish to
parse everything in just the first ppro arg, or contents of all the
ppro args.
> > Hmm. Not sure you can pass a map to a plugin. I forget, will
check
> > it out.
> >
>
> The reason I passed a map to the plugin is primarily to get my
output
> values back. I stole this interface idea from Perl. It's very
> convenient. The returned map element keys are named after the
syntax
> options, and the corresponding values are set to whatever was
parsed. So
> one can script
>
> if(opts["x"])do
> win.debug("option -x (or --xlongform) specified as",opts["x"])
> endif
>
> Hmm, unfortunately, I just realized that the map plugin is missing
a
> service to determine whether a map KEY exists. Without that service-
-
> which Perl does have--it's impossible to support this interface.
Let's
> assume for a moment that there was such a service,
map.IsKeyDefined,
> then the right scriptlet would be:
>
> if( map.IsKeyDefined(opts,"x") )do
> win.debug("option -x (or --xlongform) specified as",opts["x"])
> endif
>
> Without IsKeyDefined there would be no way for an Options plugin to
> return values for a -y option that doesn't require an argument.
>
> > Failing that, you could pass a single string, made of multiple
lines
> > (separated by newline), one line per arg
> >
>
> Yes, but how do return values? Possibly in a simple way? I still
like
> the Perlish way better, assuming that it's technically feasible in
> PowerPro.
That's easy. You pass in the name of a variable, either as part of a
map or part of a string. plugin sets that variable (which
unfortunately has to be global, ASAIK). So after call to plugin, the
variables you specified are set (if it's a flag, probaby set the
specified var with 0/1).
> > Or you theree could be
> >
> > options.addIntArg("c", "count", "number", "number of copies to
> > print.")
> >
> > Also options.addBoolArg, options.addStringArg....
> >
>
> Yes, this is good, too. Still the key question to me is how to
return
> values in a simple way.
See above.
Meanwhile decided better (to avoid race conditions between several
scripts trying to use plugin at same instant) to _not_ have time gap
between time you set the parsing rules and time you get result.
Better to do as you originally suggested and have just one plugin
service,
options.eval(<the rules in some form>,<the arguments to parse>)
> > ; parse script arguments
> >> local error = Options.syntax(opts, syntax, args)
> >> ; on error print usage message and quit
> >> if(error)do
> >> for(i=word(opts["USAGE"]; i>0; i=i-1)do
> >> win.debug(word(opts["USAGE"],i)
> >> quit(-1)
> >> endif
> >
> > Or the plugin raises a script error dialog if the syntax is wrong?
> >
>
> I hate when PP or plugins raise error dialogs. I want to be able to
> control the user interface of my scripts.
That'sokay, my standard plugin form has a service to turn error
dialogs on and off.
> >> ; process options
> >> if(opts["x"])do
> >> win.debug("-x", opts["x"], "was specified")
> >> ; etc.
> >> endif
> >> ; etc.
> >
> > Or options.go(theArgsToParse)
> > options.getParsedArg(index)
> >
>
> Your options.go() is the same as my options.syntax() right?
Yup. But now I prefer all-in-one-go service, because of race
condition problem.
> How does options.getParsedArg(index) work? Is index a number? How
do I
> know that index corresponds to -x or -y? I still like the map
syntax
> better, if technically feasible, it makes for much more compact PP
> scripts, and it's easy to remember (at least for me with some Perl
> experience).
Yeah, it would have been an integer.
I'm pretty sure I can evaluate any ppro expression within plugin.
There are lots of properties to specify for each possible parameter:
short form
long form
is it optional
how many arguments follow it (0/1, maybe more than 1?)
if you allow only one argument, what's it type?
default value if missing
message to put out (via errordialog or return from serice)
if parameter missing
Depending on what I'm allowed to do, you could do this
options.eval(<vector of maps>, <string to evaluate>)
There would be one map for each parameter, with
elements "short", "long", "optional", "resultvar"....
Or, this:
options.eval(<vector of short names>,
<vector of long names>,
<vector of ppro var names>,
<vector of "is it optional" flags>,
<vector of default values>,
<string to evaluate>)
Wanna copy your reply to me at [EMAIL PROTECTED] ?
As no one else is adding to this thread, maybe best to continue it by
e-mail.
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/JV_rlB/TM
---------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/power-pro/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/