Noah Cain
Noah Cain

Reputation: 23

How do I parse command line arguments in Dart?

I am trying to get commands and flags to work in Dart, but I can't seem to figure out how to get the input from the user when running the command. I have the args package, and I am able to get it to work with basic things, like flags (-a, --help, etc), but I would like the user to be able to type a command, for example, git commit -m "hello", but I can not figure out how to get the last part of the command to work, with the custom input. How is it done? Are there any examples?

Upvotes: 1

Views: 1408

Answers (1)

lrn
lrn

Reputation: 71613

The command line arguments are available as a list of strings passed to the main function.

void main(List<String> args) { ... }

You can parse them directly from there using your own code, write your own general flag parser, or you can use the existing args package, which comes with documentation saying how to use it.

Most people use the args package.

Upvotes: 3

Related Questions