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
How in Dart get command line arguments outside of the main
method?
#18369
Comments
cc @lrhn. |
I don't believe there are any current plans to bring back a way to get the arguments to main from outside of main. If your main function needs the arguments, it should either process them, or store them somewhere. If you are not in control of the main function (e.g., as a library), you can use a -D option to pass in configuration options. This is a way to pass configuration options to your program on the command line. Normal command line arguments are only intended as arguments to the main function, not to the system itself. Removed Type-Defect label. |
As lrn@ said, this is currently not planned. Just like most other programs, arguments are received by the main method. It can then choose what to do with them. lrn@ does suggest a quite viable work-around. This should be considered if there is an absolute need for sharing 'arguments' as described. Added NotPlanned label. |
For this particular case, you would need to add to your task package an initialization function that takes the parameters. main(args) { or the more imperative: |
This comment was originally written by andrew.m...@gmail.com
Your don't think about that the "Why other platforms does not consider that 'command line arguments are only intended as arguments to the main function'?". main(args) { "initializeTasks(args)" seems here as if it were happening in the last century in Fortran language. With this approach, you will not have a chance to compete with other languages. Go language =========== Rust language =========== =========== =========== print(sys.argv) =========== =========== =========== |
There are plenty of examples in both directions. The main problem with a global way to access command line arguments is exactly that it is global, and therefore inherits all the problems of global variables. If a library is built to read a global It also makes it possible to call a There is nothing you can't do with one approach that you can't do with another, you just have to explicitly pass the arguments to whoever needs them. So, yes, it is indeed "unneeded" (but then, most of everything is when your language is Turing complete) and we have chosen another approach than the languages you picked out - the same approach as a number of other languages that you didn't list. |
This comment was originally written by andrew.m...@gmail.com
Yes. I want get real arguments that given by the OS when it executes the the OS PROCESS but not the "surrogate" arguments that can be passed to "main" in each THREAD. This is a big difference and if it not so often used then this not means that this is unneeded. Command line arguments and arguments that passed to the "main in Dart can differs but the real arguments can be only one that goes from OS (Dart VM in our case). Why you want hide them? P.S. This is not a language approach. This is a platform specific approach. P.S. Example. =========== Not a language specific because uses "process.argv". Dart platform has no moral right to deprive me of the opportunity to receive this information in any other way (not through "main"). This is very bad approach to think that if you not need them then YOU MUST HIDE them deeply inside virtual machine. |
This comment was originally written by andrew.m...@gmail.com =========== Not a language specific because uses "process.argv". P.S. Honestly, I was not sure that you are able to understand me because you chose to hide them. You you not feel difference between two different things such a following:
You you not feel difference between two different things such a following:
How can we talk about something you after such a misunderstanding of each other? But how can you not understand the basic concepts, I do not understand you. |
This comment was originally written by andrew.m...@gmail.com print(Platform.executableArguments); Output: Whay you truncate them. How I get full arguments. I want parse them. /home/andrew/tools/dart/dart-sdk/bin/dart --enable-checked-mode --debug:60514 test.dart But I just want get the following part "test.dart foo --baz". But I agree, and full part /home/andrew/tools/dart/dart-sdk/bin/dart --enable-checked-mode --debug:60514 test.dart Because I can parse it and find information which I need. Why you hide this full argrumnts? Platinum rule: |
This comment was originally written by @seaneagan @LRN: Global variables do not prevent a library from taking the state as an argument, but they do allow libraries to provide a sensible default value for the state argument for production code or scripts that don't need to mock out, or otherwise inject the state. Of course, not providing the global variable does force people to make their code testable. But, it seems weird to me that all the other state passed in from the computing environment is available through global state, including all the Platform static variables, and -D parameters. This would be nice for: http://pub.dartlang.org/packages/unscripted Example: main() => declare(script).execute(); |
This comment was originally written by andrew.m...@gmail.com
The same thing. void main() { vs main(args) { |
This comment was originally written by andrew.m...@gmail.com No problem. I can write it by himself using shell. ps-p XXXX-o cmd = On Windows I also can solve this. Now two basic questions to very smart @ lrn.
Another question that you can not answer: |
This comment was originally written by andrew.m...@gmail.com @seaneagan1 I also trying to write similar. Assume I want write in Dart shell similar to Spring "roo". Example: dartshell.yaml Now source code var helper = new ArgsHelper<MyProgram>(); class MyProgram { |
Removed Area-IO label. |
This comment was originally written by @kaendfinger I'm going to challenge myself by figuring this out. |
This comment was originally written by @kaendfinger |
Issue #22466 has been merged into this issue. |
This comment was originally written by @kaendfinger In my personal view, the benefits outweigh the negatives. Maybe sometime in the future this decision can be re-evaluated once usage of Dart is more vast. |
This issue was originally filed by andrew.m...@gmail.com
Question on StackOverflow.com:
http://stackoverflow.com/questions/23221556/how-in-dart-get-command-line-arguments-outside-of-the-main-method
In C# langauge exists global system variable for this purpose.
Environment.CommandLine
This property provides access to the program name and any arguments specified on the command line when the current process was started.
Dart is asynchronous langauge. It allows self starting processes.
void main() {
task("foo", callback1);
task("baz", callback2);
}
Package tasks.
void task(String name, action()) {
schedule();
addTask(name. action);
}
void schedule() {
// Here we start timer if it not started.
// This timer will get cmd line arguments
// And executes task specified in cmd line arguments
}
===================================
I want implement in Dart build tool similar to Ruby rake.
For this purpose I implemented the "globbing" package.
I need get the command line arguments from "dart:io" "Platform" class.
Can you implement this quickly?
Similar to this code:
class Platform {
static List<String> get arguments;
}
The text was updated successfully, but these errors were encountered: