- Subject: Re: [slang-users] Re: cmdopt
- From: jed@xxxxxxxxxxx (John E. Davis)
- Date: Wed, 12 Aug 2015 10:27:09 -0400
Morten Bo Johansen <mbj@xxxxxxxxxxx> wrote:
> Did I misunderstand or wasn't the above supposed to print all
> the arguments to the "-b" switch? If I do
>
> <script> -b a b c
>
> then with the above it should print "abc"? However, only the
> first argument is pushed onto the list so it prints only "a".
Switches do not support more than 1 argument. I suggest that you try
something like:
<script> -b a,b,c
The corresponding script is appended below.
I hope this helps.
Thanks,
--John
#!/usr/bin/env slsh
require ("cmdopt");
private define p (a)
{
() = printf ("%s\n", a);
}
private define print_csv (csv)
{
variable args = strchop (csv, ',', 0);
p (strjoin (args));
}
define slsh_main ()
{
variable c = cmdopt_new ();
c.add ("a", &p; type="str");
c.add ("b", &print_csv; type="str");
variable i = cmdopt_process (c, __argv, 1);
message ("Unhandled arguments:");
while (i < __argc)
{
vmessage (" argv[%d] = %s", i, __argv[i]);
i++;
}
}
[2015 date index]
[2015 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]