Implement C-like command line arguments in Julia

There is a way to reproduce C command line arguments behavior in Julia?

int main(int argc, char **argv) { /* ... */ }
1 Like

I used DocOpt.jl in the past and liked it. But I remember a newer approach as well. If I remember the link I will share here.

1 Like

Here it is: https://github.com/comonicon/Comonicon.jl

4 Likes

At the lowest level, the equivalent of the C argc/argv variables is the ARGS global constant, which is a list of strings giving the command-line arguments passed by the user.

On top of that, there are various higher-level packages to help you parse command-line arguments. For example, an analogue of the C getopt API in Julia is provided by the ArgParse package, and then there are also the abovementioned DocOpt and Comonicon packages.

8 Likes

I was just investigating the same question, and a bit surprised that one needs to install a third-party package for that. Shouldn’t it be a part of the standard library? Besides, looking at the GitHub repos (in November 2025):

  • DocOpt.jl - looks abandoned: src is updated 4 years ago, tests 7 years ago
  • Comonicon.jl the repo is updated 8 months ago, OK, however the last release is in May 2024 and the CI badge says “failing”
  • ArgParse.jl looks the most maintained right now, although the last release is also May 2024.

The standard is that you get a vector of strings, beyond that, you can really do anything you want with those strings so I’m not sure how parsing that could be a good candidate for Base functionality. There’s just too many approaches to it.

@jules I think I am too spoiled by Python :slight_smile:

UPDATED: On a second thought, there are components in the standard library like LibGit2, Tar, and Markdown, which look to me much more tangential to day-to-day programming tasks than parsing command-line arguments.

For those specific examples, LibGit2 and Tar are critical components for the (built in) package manager and Markdown is used to present docstrings within the Julia REPL.

2 Likes

Sure it can be nice if something is available by default, but even the python docs for argparse, which I assume you mean, say right at the top:

While argparse is the default recommended standard library module for implementing basic command line applications, authors with more exacting requirements for exactly how their command line applications behave may find it doesn’t provide the necessary level of control. Refer to Choosing an argument parsing library for alternatives to consider when argparse doesn’t support behaviors that the application requires (such as entirely disabling support for interspersed options and positional arguments, or accepting option parameter values that start with - even when they correspond to another defined option).

In Julia, I think we generally err on the side of not putting stuff into Base in such cases although arguments can be made for either position.

2 Likes