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

Arg module bug #8372

Closed
vicuna opened this issue Nov 18, 2003 · 2 comments
Closed

Arg module bug #8372

vicuna opened this issue Nov 18, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 18, 2003

Original bug ID: 1931
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi
I found that Arg module will always print more than what i want.
For example
some code:

let main () =
let speclist = [
("-t", Arg.String( print_endline) ,
"File types ");
("-v", Arg.String(print_endline) ,"show version information");
] in
let ano_fun s =
print_endline "Default"
in
Arg.parse speclist ano_fun "command [-t type] [-v string] "

let _ =
main();;

after complie as output ptk
when i type
./ptk -t
it will print the error message 3 time !

[climb@lcgfdr prj]$ ./ptk -t
./ptk: option -t' needs an argument. command [-t type] [-v string] -t File types -v show version information -help Display this list of options --help Display this list of options ./ptk: ./ptk: option -t' needs an argument.
command [-t type] [-v string]
-t File types
-v show version information
-help Display this list of options
--help Display this list of options
.
command [-t type] [-v string]
-t File types
-v show version information
-help Display this list of options
--help Display this list of options

and when i type
./ptk -t -v
it will print -v.
it will not print any error mesage.
however at this situation , it is a error input of args

Since i am new to Arg module , i am not quite sure is it a bug or not.
If not a bug, can you tell me how to avoid it ?

climb

@vicuna
Copy link
Author

vicuna commented Nov 19, 2003

Comment author: administrator

Hello,

I found that Arg module will always print more than what i want.

./ptk -t
it will print the error message 3 time !

This is a bug. It is now fixed in the CVS version.

and when i type
./ptk -t -v
it will print -v.
it will not print any error mesage.
however at this situation , it is a error input of args

This is not a bug. The argument to "-t" is an arbitrary string, and it can
start with a "-". If we do otherwise, it becomes impossible to pass an
argument that starts with "-" to an option, and that would be too limiting.

Since i am new to Arg module , i am not quite sure is it a bug or not.
If not a bug, can you tell me how to avoid it ?

If you want to forbid a leading "-" in the "-t" argument, you need to
test it yourself as follows:

let check_t s =
if String.length s > 0 && s.[0] = '-'
then raise (Arg.Bad "bad argument to -t")
else print_endline s
;;

let speclist = [
("-t", Arg.string check_t, "File types");
...
]

Thank your for your bug report.

-- Damien

@vicuna
Copy link
Author

vicuna commented Nov 19, 2003

Comment author: administrator

fixed DD 2003-11-19

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

No branches or pull requests

1 participant