And does Dart have a getopt library?
Tomas Kulich
Using Options is no longer an option, use:
void main(List<String> args) {
print(args);
}
To get executable, use Platform.executable (Platform comes from dart:io)
For parsing arguments passed to main, use this cool package
Edit: This is no longer valid, see accepted answer above.
See Options
.
http://api.dartlang.org/dart_io/Options.html
List<String> argv = (new Options()).arguments;
igor
// dart 1.0
import 'dart:io';
void main(List<String> args) {
String exec = Platform.executable;
List<String> flags = Platform.executableArguments;
Uri script = Platform.script;
print("exec=$exec");
print("flags=$flags");
print("script=$script");
print("script arguments:");
for(String arg in args)
print(arg);
}
mcandre
#!/usr/bin/env dart
main() {
print("Args: " + new Options().arguments);
}
I use this library for defining and parsing command line args http://pub.dartlang.org/packages/args
来源:https://stackoverflow.com/questions/9279541/how-do-i-access-argv-command-line-options-in-dart