Forums

Command Line Arguments

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Command Line Arguments

Postby dennis » Thu Feb 21, 2008 9:34 pm

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?
dennis
 
Posts: 21

Re: Command Line Arguments

Postby Charles » Thu Feb 21, 2008 9:59 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Command Line Arguments

Postby hopscc » Fri Feb 22, 2008 1:24 am

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
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Command Line Arguments

Postby Dafra » Fri Feb 22, 2008 10:37 am

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
Dafra
 
Posts: 12

Re: Command Line Arguments

Postby Charles » Fri Feb 22, 2008 8:28 pm

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".
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Command Line Arguments

Postby dennis » Fri Feb 22, 2008 11:15 pm

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?
dennis
 
Posts: 21

Re: Command Line Arguments

Postby Charles » Sat Feb 23, 2008 2:16 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Command Line Arguments

Postby Charles » Sat Feb 23, 2008 2:17 am

Oh yeah, -debug now implies -debugging-tips:no per your request.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Command Line Arguments

Postby Dafra » Sat Feb 23, 2008 7:12 am

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.
Dafra
 
Posts: 12

Re: Command Line Arguments

Postby Charles » Sat Feb 23, 2008 10:57 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 106 guests

cron