Skip to content

Cookbook recipes to parse command-line arguments #3038

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

boechat107
Copy link
Contributor

The recipes in this PR contains three alternative ways to parse command-line arguments:

  1. Manipulating Sys.argv directly.
  2. Using the Arg module from the standard library.
  3. Using Cmdliner installed through opam.

@boechat107
Copy link
Contributor Author

I can't understand why the CI failed. I'll investigate ood-gen.

If someone has seeing this before, I would appreciate any help.

Comment on lines 21 to 27
let arg_module_parser () =
let usage_msg =
"mycmd [--verbose] <file1> [<file2>] ... -o <output>"
and verbose = ref false
and input_files = ref []
and output_file = ref "" in
(* This function is called once for each anonymous argument. *)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ood-gen is parsing this whole block as a Str.Text, except for the final delimiter *). There seems to be something wrong with the string splitting (Str.full_split, line 72).

Copy link
Contributor Author

@boechat107 boechat107 Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. The regex expect the delimiter (* always at the beginning of the line. This code has indented comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any comments about this comments restriction. Would it make sense to add a comment? Or would it be better to change the regex pattern?

"ood-gen" uses a regex pattern that expects comments starting only at the
beginning of lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants