Page 1 of 3

Command Line Arguments

PostPosted: Thu Feb 21, 2008 9:34 pm
by dennis
When I try to pass argument bar to program foo in this command:

Code: Select all
cobra -d foo bar


I get the error message:

Code: Select all
cobra: error: Cannot find "bar" as a file.


How do I pass an argument in this scenario?

Re: Command Line Arguments

PostPosted: Thu Feb 21, 2008 9:59 pm
by Charles
Cobra allows multiple files to be passed on the command line:
Code: Select all
cobra -d foo bar baz

Consequently, it processes all the arguments. The only workaround is to split into compilation vs. running:
Code: Select all
cobra -d -c foo bar baz
foo
# or on mono:
cobra -d -c foo bar baz
mono --debug foo.exe

Yes, that's lame. One solution could be to provide a double dash separator:
Code: Select all
cobra -d foo bar baz -- arg1 arg2
cobra myprog -- arg1 arg2

Or we could constrain cobra to either one source file or a -files argument:
Code: Select all
cobra -d foo arg1 arg2
cobra -d -files:foo,bar,baz arg1 arg2

I suppose the constraint could be removed in the presence of the -c flag.

I'd like to hear feedback on these and other ideas.

Re: Command Line Arguments

PostPosted: Fri Feb 22, 2008 1:24 am
by hopscc
Is it likely if you're doing a compile and run you'd be specifying more than 1 src file or have more than one files arg??
its a convenience after all

I think constraining both of those to 1 arg is probably acceptable..
If you're doing just a compile (-c) it doesnt matter - take all the args given as now

Re: Command Line Arguments

PostPosted: Fri Feb 22, 2008 10:37 am
by Dafra
The D compiler has a "-run" option for the one file that is executed and its arguments.
Code: Select all
cobra lib1 lib2 -run main arg1 arg2

Re: Command Line Arguments

PostPosted: Fri Feb 22, 2008 8:28 pm
by Charles
Thanks for the feedback. I found the D approach informative and I agree with hopscc that a compile and run with multiple files is probably the exception.

I really don't want to lose the convenience of saying "cobra prog". So my current thinking is:
Code: Select all
cobra prog
# compiles and runs foo

cobra prog foo bar
# compiles and runs prog, passing foo and bar as arguments

cobra -c prog lib1 lib2
# compiles all. there can be no arguments passed on, because this is compilation only

cobra lib1 lib2 -run prog foo bar
# compiles and runs passing everything after prog as arguments

# of course, nothing prevents you from being explicit:
cobra -run prog
cobra -c prog

Finally, I'm tempted to change the current -r (which is short for -ref) to a synonym for -run to balance out with -c. Note that Cobra will at some point automatically -ref the DLLs you use in your source such as "use System.Windows.Forms".

Re: Command Line Arguments

PostPosted: Fri Feb 22, 2008 11:15 pm
by dennis
I like your "current thinking".

What about -libs:

Code: Select all
cobra -libs lib1 lib2 -run prog foo bar
# compiles and runs passing everything after prog as arguments


With debug it might look like this:

Code: Select all
cobra -d -libs lib1 lib2 -run prog foo bar
# compiles and runs passing everything after prog as arguments


Without -libs, it might look kind of funny.

edit: BTW, If the -debug option is specified, maybe the "Cobra debugging tips" message could be turned off?

Re: Command Line Arguments

PostPosted: Sat Feb 23, 2008 2:16 am
by Charles
So without -libs we might have:
Code: Select all
cobra -d Customer Quote Order LineItem Product -run Main -test 13

I think I'm okay with that.

Another case to be supported, given that cobra.exe already supports -files:
Code: Select all
# compile only
cobra -d -c -files.text
# if you want to run right away:
cobra -d -files:files.text -run arg1 arg2

Probably won't come up much, but just for completeness.

Re: Command Line Arguments

PostPosted: Sat Feb 23, 2008 2:17 am
by Charles
Oh yeah, -debug now implies -debugging-tips:no per your request.

Re: Command Line Arguments

PostPosted: Sat Feb 23, 2008 7:12 am
by Dafra
Chuck wrote:Note that Cobra will at some point automatically -ref the DLLs you use in your source such as "use System.Windows.Forms".

Some libs do not use the same name for namespace and DLL, so a mechanism to explicitly reference DLLs will be needed anyway.
Boo and F# have a directive to specify referenced DLLs in the source file, something like
ref "HoldemHandEval.dll"

use HoldemHand
I like that because when you download a source file, you don't have to figure out what to "-ref" with the compiler.

Re: Command Line Arguments

PostPosted: Sat Feb 23, 2008 10:57 am
by Charles
Right, Cobra already has a -ref option like C#, VB, Boo, etc. I wasn't suggesting that -ref would go away. I was suggesting that Cobra try to locate Foo.Bar.dll when (a) your code says "use Foo.Bar" and (b) there is no "Foo.Bar" namespace referenced in your DLLs. If you're familiar with Python, you can see this is clearly inspired by Python's import statement. I believe Boo has this, but C# does not.