Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005197OCamlOCaml generalpublic2010-12-15 07:592014-04-01 12:31
Reporterguesdon 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version3.12.0 
Target VersionFixed in Version 
Summary0005197: Ability to define --foo= options in Arg
DescriptionHello,

It seems that the standard way to define and use command line options is the following:
- one-char options which take an argument are used with the form
  -f myarg
- long options which take an argument are used with the form
  --foo=myarg

But the Arg module doesn't allow to define the second form. It allows only
  --foo myarg

Would it be possible to allow the specification of such options ? Maybe by adding constructors to the Arg.spec type ?

Maxence
TagsNo tags attached.
Attached Filespatch file icon 0001-stdlib-arg-Allow-flags-such-as-flag-arg-as-well-as-f.patch [^] (5,670 bytes) 2013-11-09 10:26 [Show Content]

- Relationships

-  Notes
(0005906)
doligez (administrator)
2011-05-17 17:04

I don't understand the need to annoy your users by forcing them to type = instead of the large easy-to-find space bar...

The best way to implement this without polluting arg.mli too much is probably to add an optional argument to parse and parse_argv to tell them to accept = as a separator between flag and argument.
(0010610)
Richard Jones (reporter)
2013-11-09 09:17

I think Arg should work like GNU getopt_long, ie. accept both --arg foo and --arg=foo.

Someone has noted that our virt-* tools written in OCaml don't behave in the expected way (https://bugzilla.redhat.com/show_bug.cgi?id=1028650 [^]).

I will try to come up with a suitable patch to the Arg module to allow it to accept both.
(0010611)
Richard Jones (reporter)
2013-11-09 10:27

Sorry, I uploaded the wrong file first time. Please delete the first attachment (I can't work out how to delete attachments in Mantis).

I am testing this patch:
0001-stdlib-arg-Allow-flags-such-as-flag-arg-as-well-as-f.patch
(0010661)
Richard Jones (reporter)
2013-11-21 12:34

FWIW I have been trying out my patch since 2013-11-09 with no
apparent problems. I have pushed this patch into Fedora to get
wider testing.
(0011147)
alavrik (reporter)
2014-04-01 09:13

It looks like there may be a problem with this patch (assuming this is the same one that was pushed with the current Fedora).

The actual problem seems to be that Arg.current has incorrect value (at least in some cases). The value is off by +1 from the value in the stock OCaml version.

Please see this discussion for the details and steps to reproduce the problem: https://groups.google.com/d/msg/piqi/SZ97hEf8j7I/taK1eUx-AigJ [^]

And here's the actual code that exposes the difference in behavior: https://github.com/alavrik/piqi/blob/master/piqilib/piqi_getopt.ml#L349 [^]
(0011149)
Richard Jones (reporter)
2014-04-01 10:16

Do you have a tiny reproducer of the bug?
(0011151)
Richard Jones (reporter)
2014-04-01 10:47

OK here's my reproducer:

--------
(* Run: argtest -- 1 2 3 *)
let rest_fun arg =
  Printf.printf "current = %d, arg = %s\n" !Arg.current arg
let argspec = [ "--", Arg.Rest rest_fun, "sep" ]
let anon_fun arg =
  Printf.printf "current = %d, anon = %s\n" !Arg.current arg
let () = Arg.parse argspec anon_fun "usage"
--------

Without the patch, prints:

$ ./argtest -- 1 2 3
current = 1, arg = 1
current = 2, arg = 2
current = 3, arg = 3

With the patch, prints:

$ ./argtest -- 1 2 3
current = 2, arg = 1
current = 3, arg = 2
current = 4, arg = 3

So this is a real bug, I'll see what is causing it and update the
patch and the Fedora package.
(0011153)
Richard Jones (reporter)
2014-04-01 12:31

Please can someone delete the attachment.

The following two patches should fix the bug properly without changing
the order in which Arg.current is incremented:

http://oirase.annexia.org/tmp/0001-arg-Add-no_arg-and-get_arg-helper-functions.patch [^]
http://oirase.annexia.org/tmp/0002-arg-Allow-flags-such-as-flag-arg-as-well-as-flag-arg.patch [^]

This only affects Fedora 21, and I will push a fix for it shortly.

- Issue History
Date Modified Username Field Change
2010-12-15 07:59 guesdon New Issue
2011-05-17 17:04 doligez Note Added: 0005906
2011-05-17 17:04 doligez Status new => acknowledged
2013-10-07 16:25 doligez Status acknowledged => confirmed
2013-11-09 09:17 Richard Jones Note Added: 0010610
2013-11-09 10:26 Richard Jones File Added: 0001-builder-Old-OCaml-didn-t-have-List.iteri-so-add-a-ut.patch
2013-11-09 10:26 Richard Jones File Added: 0001-stdlib-arg-Allow-flags-such-as-flag-arg-as-well-as-f.patch
2013-11-09 10:27 Richard Jones Note Added: 0010611
2013-11-09 11:05 protz File Deleted: 0001-builder-Old-OCaml-didn-t-have-List.iteri-so-add-a-ut.patch
2013-11-21 12:34 Richard Jones Note Added: 0010661
2014-04-01 09:13 alavrik Note Added: 0011147
2014-04-01 10:16 Richard Jones Note Added: 0011149
2014-04-01 10:47 Richard Jones Note Added: 0011151
2014-04-01 12:31 Richard Jones Note Added: 0011153


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker