Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to define --foo= options in Arg #5197

Closed
vicuna opened this issue Dec 15, 2010 · 11 comments
Closed

Ability to define --foo= options in Arg #5197

vicuna opened this issue Dec 15, 2010 · 11 comments
Assignees

Comments

@vicuna
Copy link

@vicuna vicuna commented Dec 15, 2010

Original bug ID: 5197
Reporter: @zoggy
Assigned to: @damiendoligez
Status: closed (set by @damiendoligez on 2015-11-25T21:27:51Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.12.0
Fixed in version: 4.03.0+dev / +beta1
Category: ~DO NOT USE (was: OCaml general)
Tags: github, patch
Monitored by: "Richard Jones"

Bug description

Hello,

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

@vicuna
Copy link
Author

@vicuna vicuna commented May 17, 2011

Comment author: @damiendoligez

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.

@vicuna
Copy link
Author

@vicuna vicuna commented Nov 9, 2013

Comment author: Richard Jones

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.

@vicuna
Copy link
Author

@vicuna vicuna commented Nov 9, 2013

Comment author: Richard Jones

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

@vicuna
Copy link
Author

@vicuna vicuna commented Nov 21, 2013

Comment author: Richard Jones

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.

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 1, 2014

Comment author: alavrik

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

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 1, 2014

Comment author: Richard Jones

Do you have a tiny reproducer of the bug?

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 1, 2014

Comment author: Richard Jones

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.

@vicuna
Copy link
Author

@vicuna vicuna commented Apr 1, 2014

Comment author: Richard Jones

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.

@vicuna
Copy link
Author

@vicuna vicuna commented Aug 6, 2014

Comment author: @gasche

Note: The two patches are available for review as a github request:
#63

@vicuna
Copy link
Author

@vicuna vicuna commented Nov 25, 2015

Comment author: @damiendoligez

Fixed bug, added changelog entry and test, merged into trunk (commit 2512b48).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants