How do I access argv / command line options in Dart?

江枫思渺然 提交于 2019-12-01 04:51:37

问题


And does Dart have a getopt library?


回答1:


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




回答2:


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;



回答3:


// 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);
}



回答4:


#!/usr/bin/env dart

main() {
    print("Args: " + new Options().arguments);
}



回答5:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!