Ticket #12: cmdLnArgs-NEW-part1and2.patch
File cmdLnArgs-NEW-part1and2.patch, 15.0 KB (added by hopscc, 16 years ago) |
---|
-
HowTo/600-AccessMySQL.cobra
1 1 # .require. MySql.Data.dll 2 # .args. -r :System.Data -r:MySql.Data2 # .args. -ref:System.Data -ref:MySql.Data 3 3 """ 4 4 See also: 5 5 docs/mysql on the Cobra web site … … 11 11 http://dev.mysql.com/doc/refman/5.0/en/connector-net-installation-unix.html 12 12 13 13 To run: 14 cobra -r :System.Data -r:MySql.Data AccessMySQL.cobra14 cobra -ref:System.Data -ref:MySql.Data AccessMySQL.cobra 15 15 16 16 Or just compile: 17 cobra -c -r :System.Data -r:MySql.Data AccessMySQL.cobra17 cobra -c -ref:System.Data -ref:MySql.Data AccessMySQL.cobra 18 18 and then run: 19 19 mono mysql.exe 20 20 21 You can probably leave out the "-r :<library>" and rely of `use` to locate these.21 You can probably leave out the "-ref:<library>" and rely of `use` to locate these. 22 22 23 23 Mac OS X: 24 24 For installation, MySQL docs say "Copy the MySql.Data.dll file to your Mono project installation folder." -
Source/Compiler.cobra
482 482 483 483 484 484 def runProcess as Process 485 return .runProcess(nil, nil) 486 487 def runProcess(exeName as String?, argList as List<of String>?) as Process 485 488 """ 486 489 Returns a new Process with startInfo.fileName and p.startInfo.arguments set appropriately 487 for the produced executable and the current options .490 for the produced executable and the current options and any provided argslist. 488 491 """ 489 # TODO: support args to the program with a - or -- separator490 492 p = Process() 493 baseExeFileName = exeName ? .baseExeFileName 494 fullExeFileName = exeName ? .fullExeFileName 491 495 branch .platform 492 496 on PlatformEnum.Microsoft 493 p.startInfo.fileName = .baseExeFileName497 p.startInfo.fileName = baseExeFileName 494 498 on PlatformEnum.Novell 495 499 p.startInfo.fileName = 'mono' 496 500 args = '' 497 501 # mono also needs --debug when running 498 502 if .options.getDefault('debug', '') not in ['', '-'] 499 503 args += '--debug ' 500 args += '"[ .fullExeFileName]"'504 args += '"[fullExeFileName]"' 501 505 p.startInfo.arguments = args 502 506 else 503 507 throw FallThroughException(.platform) 508 509 if argList and argList.count 510 args = p.startInfo.arguments ? '' 511 args += Utils.join(' ', argList) 512 p.startInfo.arguments = args 504 513 return p 505 514 506 515 ## … … 751 760 print ' |', line 752 761 return refs 753 762 754 parts = output.replace('-r :', '\0').split(c'\0')763 parts = output.replace('-ref:', '\0').split(c'\0') 755 764 for part in parts 756 765 if part.trim <> '', refs.add(part.trim) 757 766 -
Source/CommandLine.cobra
8 8 class CommandLine 9 9 """ 10 10 The main options that control the command line's behavior are: 11 run 11 run-exe 12 12 test 13 13 compile 14 14 testify … … 16 16 17 17 "testify" is private to the implementor of Cobra. 18 18 19 "run " is the default if none are specified and at least one path is provided.19 "run-exe" is the default if none are specified and at least one path is provided. 20 20 21 21 If no arguments are passed at all, "help" becomes the default. 22 22 … … 199 199 }, 200 200 { 201 201 'name': 'reference', 202 'synonyms': ['r '], # TODO: lose 'r' ->'Ref', 'R', something else202 'synonyms': ['ref'], 203 203 'isAccumulator': true, 204 204 'description': 'Add a DLL reference.', 205 205 'args': 'Some.dll', … … 218 218 # 'args': ':Qualified.Type.Name', 219 219 # }, 220 220 { 221 'name': 'run', # TODO: Synonym 'r' after change 'reference' switch 221 'name': 'run-exe', # run-prog?? this is a switch only 222 'synonyms': ['r'], 222 223 'description': 'Runs the Cobra program. This is the default behavior if specify any Cobra source files.', 223 224 'type': 'main', 224 225 }, 226 { 227 'name': 'run-args', 228 'synonyms': ['-'], # '--' 229 'description': 'Remaining args are to be passed to executable.', 230 'eg': '-- arg1 arg2 argThree', 231 'type': 'args-list', 232 }, 233 { 234 'name': 'run', 235 # 'synonyms': ['X'], 236 'description': 'First arg following is executable to run, remainder are to be passed to executable.', 237 'eg': '-run progname arg1 arg2 argThree', 238 'type': 'args-list', 239 }, 225 240 { 226 241 'name': 'sharp-compiler', 227 242 'description': 'Specify the path to the backend C# compiler.', … … 357 372 print ' [path]' 358 373 if options.boolValue('testify') 359 374 .doTestify(paths) 360 else if options.boolValue('run ')375 else if options.boolValue('run-exe') # was 'run' 361 376 .doRun(paths) 362 377 else if options.boolValue('test') 363 378 .doTest(paths) … … 485 500 if .options.boolValue('compile') # maybe changed by compiler directive 486 501 return 487 502 488 p = c.runProcess 503 exeFileName as String? = nil 504 runArgs = .options.getDefaultLOStr('run-args') 505 exeArgs = .options.getDefaultLOStr('run') 506 if exeArgs.count 507 exeFileName = exeArgs[0] 508 runArgs = exeArgs[1:] 509 p = c.runProcess(exeFileName, runArgs) 489 510 if _verbosity >= 1 490 511 print 'Running: [p.startInfo.fileName] [p.startInfo.arguments]' 491 512 print .verboseLineSeparator … … 635 656 valueStr = 'no-value' 636 657 fileList = List<of String>() 637 658 mainOptions = List<of String>() 659 argn = 0 638 660 for arg in args 639 if not arg.trim.length640 641 661 argn += 1 # ofset next arg after current 662 if not arg.trim.length, continue 663 642 664 isOption = arg.startsWith(optionPrefix) 643 665 if isOption 644 666 name = _getOptionParts(arg, optionPrefix, out valueStr) … … 649 671 continue 650 672 651 673 value = _processToValue(name, valueStr, spec, mainOptions) 674 if value == 'args-list' 675 value = args[argn:] 652 676 if value is nil 653 677 _error('Cannot process value "[valueStr]" for option "[name]".') 654 678 valueDict[name] = value to ! 655 679 didSpecify[name] = true 680 if spec['type'] to String == 'args-list' 681 break # absorbed remainder of args 656 682 else # not isOption 657 683 if _optsOnly 658 684 _error("Filenames are not allowed here, All the args provided must be '-' prefixed options") … … 691 717 """ 692 718 while arg.startsWith(optionPrefix) 693 719 arg = arg[1:] 720 if not arg.length # '--' 721 arg = 'run-args' 694 722 return arg 695 723 696 724 def splitOpt(arg as String) as IList<of String> … … 799 827 on 'main' 800 828 mainOptions.add(name) 801 829 value = true 830 on 'args-list' # remainder of args are for execution of exe file 831 value = 'args-list' 802 832 else 803 833 value = _interpretValue(valueStr, spec) 804 834 return value … … 953 983 print ' cobra <options> <command> <path(s)>' 954 984 print ' * commands that operate on path(s) are:' 955 985 print ' -compile ... Compile only. Also, -c' 956 print ' -run ....... Run the program (compile if necessary).'986 print ' -run-exe ... Run the program (compile if necessary). Also -r (Default)' 957 987 print ' -test ...... Run the unit tests of a library.' 958 988 print ' -document .. Document the program (partial compilation). Also, -doc' 959 989 print '' -
Tests/720-libraries/100-winforms/100-winforms.cobra
1 1 # .compile-only. 2 # .args. -c -t:winexe -r :System.Windows.Forms2 # .args. -c -t:winexe -ref:System.Windows.Forms 3 3 4 4 use System.Windows.Forms 5 5 -
Tests/320-misc-two/520-indexer-with-non-standard-name.cobra
1 # .args. -r :System.Xml1 # .args. -ref:System.Xml 2 2 3 3 # XmlNodeList has an ItemOf property instead of Item. 4 4 # This test shows that Cobra is reading the DefaultMemberAttribute of the class. -
Tests/700-command-line/705-run-args.cobra
1 # Test compile+run execution specifying args to run compiled prog with 2 class Test 3 def main is shared 4 p as System.Diagnostics.Process? 5 cobraPath = CobraCore.findCobraExe 6 assert cobraPath 7 if cobraPath 8 cmdln = "702-echo -- argA argB argC" 9 output = CobraCore.runCobraExe(cobraPath, cmdln, out p) 10 #print output 11 assert 'Unhandled Exception' not in output 12 assert 'argA argB argC' in output 13 assert p.exitCode == 0 14 15 cmdln = "702-echo -run-args x1arg1 x1argB x1argC" 16 output = CobraCore.runCobraExe(cobraPath, cmdln, out p) 17 #print output 18 assert 'Unhandled Exception' not in output 19 assert 'x1arg1 x1argB x1argC' in output 20 assert p.exitCode == 0 21 22 cmdln = "-r 702-echo -run-args x2arg1 x2argB x2argC" 23 output = CobraCore.runCobraExe(cobraPath, cmdln, out p) 24 #print output 25 assert 'Unhandled Exception' not in output 26 assert 'x2arg1 x2argB x2argC' in output 27 assert p.exitCode == 0 -
Tests/700-command-line/812-lib-option.cobra
1 1 # was .args. -lib:libdir -r:foolib -c 2 %% args -lib:libdir -r :foolib -c2 %% args -lib:libdir -ref:foolib -c 3 3 4 4 class Test 5 5 -
Tests/700-command-line/300-args-reference-gac-lib.cobra
1 # .args. -r :System.Xml1 # .args. -ref:System.Xml 2 2 3 3 use System.Xml 4 4 -
Tests/700-command-line/706-run.cobra
1 # Test execution specifying cmdln args giving exe and args after compile 2 class ExecWithArgs 3 def main is shared 4 p as System.Diagnostics.Process? 5 cobraPath = CobraCore.findCobraExe 6 assert cobraPath 7 8 # implicit run-and-execute with args 9 cmdln = "702-echo -run 702-echo argA argB argC" 10 output = CobraCore.runCobraExe(cobraPath, cmdln, out p) 11 #print output 12 assert 'Unhandled Exception' not in output 13 assert 'argA argB argC' in output 14 assert p.exitCode == 0 15 16 # implicit run-and-execute 'run-exe' no args 17 cmdln1 = "702-echo -run 110-hello" 18 output = CobraCore.runCobraExe(cobraPath, cmdln1, out p) 19 #print output 20 assert 'Unhandled Exception' not in output 21 assert 'Hello' in output 22 assert p.exitCode == 0 23 24 # explicit run-and-execute 'run-exe' using (new) synonym 25 cmdln1 = "-r 702-echo -run 110-hello AnyOldArgs AnyOldargs anyAnyOldArgs" 26 output = CobraCore.runCobraExe(cobraPath, cmdln1, out p) 27 #print output 28 assert 'Unhandled Exception' not in output 29 assert 'Hello' in output 30 assert 'AnyOld' not in output 31 assert p.exitCode == 0 32 33 # explicit'run-exe' cmd 34 cmdln1 = "-run-exe 702-echo -run 110-hello AnyNewArgs" 35 output = CobraCore.runCobraExe(cobraPath, cmdln1, out p) 36 #print output 37 assert 'Unhandled Exception' not in output 38 assert 'Hello' in output 39 assert 'AnyNewArgs' not in output 40 assert p.exitCode == 0 41 -
Tests/700-command-line/402-fooprog.cobra
1 # .args. -embed-run-time:no -r :400-foolib.dll1 # .args. -embed-run-time:no -ref:400-foolib.dll 2 2 3 3 class Program 4 4 -
Tests/700-command-line/404-fooprog.cobra
1 # .args. -embed-run-time:no -r :400-foolib1 # .args. -embed-run-time:no -ref:400-foolib 2 2 3 3 # same as other fooprog, but the -r arg does not include the ".dll" extension -- both ways should work 4 4 -
Tests/700-command-line/512-lib-option.cobra
1 1 # .compile-only. 2 # .args. -lib:libdir -r :foolib -c2 # .args. -lib:libdir -ref:foolib -c 3 3 4 4 class Test 5 5 -
Tests/700-command-line/410-use-lowernames-dll.cobra
1 # .args. -r :lowernames.dll1 # .args. -ref:lowernames.dll 2 2 3 3 class Program 4 4 -
Tests/700-command-line/702-echo.cobra
1 # .skip. 2 class Echo 3 def main is shared 4 args = CobraCore.commandLineArgs 5 sep='' 6 for a in args[1:] 7 print '[sep][a]' stop 8 sep=' ' 9 print -
Developer/IntermediateReleaseNotes.text
1 1 Post 0.8 2 2 3 * Modified commandline options and added two new capabilities: 4 previous -run becomes -run-exe (run executable). -r becomes synonym for -run-exe rather 5 than for -reference. -reference synonym becomes -ref. 6 Support -run-args (synonym --) option for specifying args to pass to compiled executable and 7 -run (no synonym) option to specify executable file and optional args to pass to it to execute after compilation. 8 3 9 * Added support for "multi-arg assignment" which allows you to assign to a number of variables from contents of a list in one statement 4 10 .code 5 11 a,b,c = ['val1', 'val2', 'val3'] 6 12 7 8 13 * Added support for a new compiler directive 'args' that takes command line options and applies them to the compilation environment from that point on. 9 14 .code 10 15 %% args -target:lib -embed-run-time:no