Changeset 1721

Show
Ignore:
Timestamp:
11/02/08 17:00:59 (2 months ago)
Author:
Chuck.Esterbrook
Message:

Command line changes

  • The default behavior for invoking the Cobra command line with no args is now -about rather than -help
  • Updated -about with more URLs for license, support, etc.

Code cleanup

Location:
cobra/trunk/Source
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CommandLine.cobra

    r1699 r1721  
    44 
    55use System.Diagnostics 
     6 
     7 
     8class OptionSpec 
     9        inherits Dictionary<of String, dynamic> 
     10        """ 
     11        Represents a specific, named command line option specification. 
     12 
     13        In addition to being a dictionary containing the original raw specification key+value pairs, 
     14        several convenient properties and methods are provided such as .name, .type and .hasDefault. 
     15        """ 
     16 
     17        var _isUnpacked = false  
     18        var _name = '' 
     19        var _type = 'unknown' 
     20        var _synonyms = List<of String>() 
     21        var _description = 'No description.' 
     22        var _isAccumulator = false 
     23        var _hasDefault = false 
     24        var _default = '' 
     25 
     26        get isUnpacked from var 
     27 
     28        get name as String 
     29                require .isUnpacked 
     30                return _name 
     31 
     32        get type as String 
     33                require .isUnpacked 
     34                return _type 
     35 
     36        get synonyms from var 
     37 
     38        get description from var 
     39 
     40        get isAccumulator from var 
     41         
     42        get hasDefault from var 
     43         
     44        get default from var 
     45                """ 
     46                Check .hasDefault before using this property for anything useful. 
     47                """ 
     48                         
     49        def isOptionSpecRestrictionViolated as bool 
     50                """ 
     51                Returns true if the option spec has a 'restriction' key and the check against that restriction is true. 
     52                """ 
     53                if .containsKey('restriction') 
     54                        branch this['restriction'] to String 
     55                                on 'mono-only' 
     56                                        return not CobraCore.isRunningOnMono 
     57                return false 
     58 
     59        def unpack 
     60                _name = this['name'] to String 
     61                try 
     62                        _type = this['type'] to String 
     63                catch KeyNotFoundException 
     64                        if .containsKey('isAccumulator') and this['isAccumulator'] to bool 
     65                                this['type'] = _type = 'accumulator' 
     66                        else 
     67                                this['type'] = 'string' 
     68                if .containsKey('synonyms') 
     69                        for syn in this['synonyms'] 
     70                                _synonyms.add(syn) 
     71                if .containsKey('description') 
     72                        _description = this['description'] 
     73                if .containsKey('isAccumulator') 
     74                        _isAccumulator = this['isAccumulator'] to bool 
     75                if .containsKey('default') 
     76                        _default = this['default'] to String 
     77                        _hasDefault = true 
     78                _isUnpacked = true 
     79 
     80 
     81class CommandLineOptionSpecs 
     82        """ 
     83        Returns the command line option specifications, via .specsList, as a List of OptionSpec. 
     84        Also, the raw option specifications are contained and maintained in this class. 
     85        """ 
     86 
     87        var _specs = List<of OptionSpec>() 
     88 
     89        def init 
     90                for rawSpec in _rawCommandLineOptionSpecs 
     91                        spec = OptionSpec() 
     92                        if rawSpec inherits Dictionary<of String, Object> 
     93                                for key in rawSpec.keys, spec[key] = rawSpec[key] 
     94                        else if rawSpec inherits Dictionary<of String, String> 
     95                                for key in rawSpec.keys, spec[key] = rawSpec[key] 
     96                        else 
     97                                throw FallThroughException(rawSpec.getType) 
     98                        spec.unpack 
     99                        _specs.add(spec) 
     100 
     101        def specsList as List<of OptionSpec> 
     102                """ 
     103                Returns the option specs in the order they were declared. 
     104                """ 
     105                return _specs 
     106 
     107        var _rawCommandLineOptionSpecs = [ 
     108                { 
     109                        'name': 'about', 
     110                        'description': 'Print the name, copyright, etc. but no usage.', 
     111                        'type': 'main', 
     112                }, 
     113                { 
     114                        'name': 'build-standard-library', 
     115                        'synonyms': ['bsl'], 
     116                        'description': 'Builds the standard library.', 
     117                        'type': 'main', 
     118                        'developer-only': true, 
     119                }, 
     120                { 
     121                        'name': 'compile', 
     122                        'synonyms': ['c'], 
     123                        'description': 'Compile the library (to DLL) or the program (to EXE) without running the code.', 
     124                        'type': 'main', 
     125                }, 
     126                { 
     127                        'name': 'color', 
     128                        'type': 'bool', 
     129                        'description': 'Colorizes the output of error messages and the messages "Compilation failed" and "Compilation succeeded" (as red, red and blue).', 
     130                }, 
     131                { 
     132                        'name': 'contracts', 
     133                        'description': 'Control treatment of code generation for contracts.', 
     134                        'type': 'menu', 
     135                        'choices': ['none', 'inline', 'methods'], 
     136                        'args': 'none|inline|methods', 
     137                        'default': 'inline', 
     138                }, 
     139                { 
     140                        'name': 'debug', 
     141                        'synonyms': ['d'], 
     142                        'type': 'string', 
     143                        'description': 'Turn on system debugging information. The value 1 implies full, which enables attaching a debugger to a running program. Turning on implies -debugging-tips:no.', 
     144                        'args': '0|1|pdbonly|full' 
     145                }, 
     146                { 
     147                        'name': 'debugging-tips', 
     148                        'description': 'Display debugging tips when an unhandled exception occurs. Overridden by -exception-report.', 
     149                        'type': 'bool', 
     150                        'default': 'yes', 
     151                }, 
     152                { 
     153                        'name': 'delay-sign', 
     154                        'type': 'bool', 
     155                        'description': 'Delay-sign the assembly using only the public portion of the strong name key.', 
     156                }, 
     157                { 
     158                        'name': 'detailed-stack-trace', 
     159                        'synonyms': ['dst'], 
     160                        'type': 'bool', 
     161                        'description': 'Enable a detailed stack trace which gives great postmortem information for uncaught exceptions, but slows execution. Works in combination with -exception-report.', 
     162                }, 
     163                { 
     164                        'name': 'embed-run-time', 
     165                        'synonyms': ['ert'], 
     166                        'type': 'bool', 
     167                        'default': 'no', 
     168                        'description': 'Embed the Cobra run-time support code (approx. 80KB) in the assembly so that no reference to an external Cobra.Lang.dll is required. If set to "no" then you should copy Cobra.Lang.dll to your current directory and also notice faster compilation time.', 
     169                }, 
     170                { 
     171                        'name': 'exception-report', 
     172                        'synonyms': ['exc-rpt', 'er'], 
     173                        'type': 'bool', 
     174                        'description': 'Turn on an informative HTML report that will be generated if the program throws an uncaught exception.', 
     175                }, 
     176                { 
     177                        'name': 'files', 
     178                        'isAccumulator': true, 
     179                        'description': 'Specify the files for Cobra to process in a separate text file. One file per line; # comments and blank lines are ignored.', 
     180                        'args': 'filename', 
     181                }, 
     182                { 
     183                        'name': 'editor', 
     184                        'type': 'string', 
     185                        'description': 'Specify an editor and command line options to invoke if there is a compile-time error. Use underscore (_) for space in the specification. Can also set via COBRA_EDITOR environment variable (in which case spaces work fine).', 
     186                        'example': ['uedit32_FILE/LINE', 'mate_FILE_-l_LINE'], 
     187                        'args': 'editor_spec_with_FILE_LINE', 
     188                }, 
     189                { 
     190                        'name': 'extra-source', 
     191                        'type': 'string', 
     192                        'args': 'SOURCE', 
     193                        'description': 'Add extra source code to be compiled with the rest. Generally used only internally by the compiler.', 
     194                        'developer-only': true, 
     195                }, 
     196                { 
     197                        'name': 'document', 
     198                        'synonyms': ['doc'], 
     199                        'type': 'main', 
     200                        'description': 'Generate HTML docs for the Cobra source.', 
     201                }, 
     202                { 
     203                        'name': 'help', 
     204                        'synonyms': ['h'], 
     205                        'type': 'main', 
     206                        'description': 'Display this help message.', 
     207                }, 
     208                { 
     209                        'name': 'include-asserts', 
     210                        'type': 'bool', 
     211                        'default': 'yes', 
     212                        'description': 'Include assert statements in the program.', 
     213                }, 
     214                { 
     215                        'name': 'include-nil-checks', 
     216                        'type': 'bool', 
     217                        'default': 'yes', 
     218                        'description': 'Include checks on non-nilable class variables, method arguments and "to !" casts.', 
     219                }, 
     220                { 
     221                        'name': 'include-tests', 
     222                        'type': 'bool', 
     223                        'default': 'yes', 
     224                        'description': 'Includes unit tests for classes and members in the output assembly.', 
     225                }, 
     226                { 
     227                        'name': 'include-traces', 
     228                        'type': 'bool', 
     229                        'default': 'yes', 
     230                        'description': 'Includes trace statements in the output assembly.', 
     231                }, 
     232                { 
     233                        'name': 'keep-intermediate-files', 
     234                        'synonyms': ['kif'], 
     235                        'type': 'bool', 
     236                        'description': 'Keeps any intermediate files that Cobra generates, which are normally deleted. Example intermediate files are *.cobra.cs.', 
     237                }, 
     238                { 
     239                        'name': 'key-container', 
     240                        'type': 'string', 
     241                        'args': 'FILE', 
     242                        'description': 'Specify a strong name key container used to strongname the output assembly.', 
     243                }, 
     244                { 
     245                        'name': 'key-file', 
     246                        'type': 'string', 
     247                        'args': 'FILE', 
     248                        'description': 'Specify a strong name key file used to sign the output assembly.', 
     249                }, 
     250                { 
     251                        'name': 'library-directory', 
     252                        'synonyms': ['lib'], 
     253                        'type': 'string', 
     254                        'isAccumulator': true, 
     255                        'description': 'Specify additional directories to search in for references.', 
     256                        'args': 'PATH', 
     257                }, 
     258                { 
     259                        'name': 'number', 
     260                        'type': 'menu', 
     261                        'choices': ['decimal', 'float', 'float32', 'float64'], 
     262                        'args': 'decimal|float|float32|float64', 
     263                        'default': 'decimal', 
     264                        'description': "Set the real numeric type for both the 'number' type and fractional literals such as '1.0'.", 
     265                }, 
     266                { 
     267                        'name': 'optimize', 
     268                        'synonyms': ['o'], 
     269                        'type': 'bool', 
     270                        'description': 'Enable optimizations.', 
     271                }, 
     272                { 
     273                        'name': 'output-html', 
     274                        'type': 'bool', 
     275                        'description': "The command line's output will be in HTML.", 
     276                }, 
     277                { 
     278                        'name': 'pkg', 
     279                        'type': 'string', 
     280                        'isAccumulator': true, 
     281                        'description': 'References package via "pkg-config --libs". (Mono only.)', 
     282                        'args': 'NAME', 
     283                        'restriction': 'mono', 
     284                }, 
     285                { 
     286                        'name': 'reference', 
     287                        'synonyms': ['ref'],  
     288                        'isAccumulator': true, 
     289                        'description': 'Add a DLL reference.', 
     290                        'args': 'Some.dll', 
     291                }, 
     292                { 
     293                        'name': 'reveal-internal-exceptions', 
     294                        'description': 'When true, uncaught exceptions from the Cobra compiler itself are not caught and wrapped in error messages. This is useful when developing on the Cobra compiler itself. Set to true if the environment variable COBRA_IS_DEV_MACHINE.', 
     295                        'type': 'bool', 
     296                        'developer-only': true, 
     297                }, 
     298# TODO 
     299#               { 
     300#                       'name': 'reflect', 
     301#                       'isAccumulator': true, 
     302#                       'description': 'Display the type interface in Cobra syntax. Use its fully qualified name.', 
     303#                       'args': ':Qualified.Type.Name', 
     304#               }, 
     305                { 
     306                        'name': 'run',          # this is a switch only    
     307                        'synonyms': ['r'],  
     308                        'description': 'Runs the Cobra program. This is the default behavior if specify any Cobra source files.', 
     309                        'type': 'main', 
     310                }, 
     311                { 
     312                        'name': 'run-args', 
     313                        'synonyms': ['-'],  # '--' 
     314                        'description': 'Remaining args are to be passed to executable.', 
     315                        'eg':          '-- arg1 arg2 arg3', 
     316                        'type': 'args-list', 
     317                }, 
     318                { 
     319                        'name': 'sharp-compiler', 
     320                        'description': 'Specify the path to the backend C# compiler.', 
     321                        'type': 'string', 
     322                        'args': 'file-system-path', 
     323                }, 
     324                { 
     325                        'name': 'sharp-args', 
     326                        'description': 'Pass additional arguments to the backend C# compiler.', 
     327                        'type': 'string', 
     328                        'args': '"arg1 arg2"', 
     329                }, 
     330                { 
     331                        'name': 'target', 
     332                        'description': 'Build a specific target.', 
     333                        'type': 'menu', 
     334                        'choices': ['exe', 'winexe', 'lib', 'module'], 
     335                        'args': 'exe|winexe|lib|module', 
     336                        'synonyms': ['t'], 
     337                }, 
     338                { 
     339                        'name': 'test', 
     340                        'description': 'Run the unit tests in the code.', 
     341                        'type': 'main', 
     342                }, 
     343                { 
     344                        'name': 'testify', 
     345                        'description': '...', 
     346                        'type': 'main', 
     347                        'developer-only': true, 
     348                }, 
     349                { 
     350                        'name': 'timeit', 
     351                        'description': 'Gives the total duration of running cobra (including the target program, if it is to be run). This is "wall time", not "cpu time".', 
     352                        # although this option is implied by 'testify', the description does not say so, since 'testify' is a hidden option 
     353                        'type': 'bool', 
     354                }, 
     355                { 
     356                        'name': 'turbo', 
     357                        'description': 'Maximum run-time performance. This is a convenience for -contracts:none -include-asserts:no -include-nil-checks:no -include-tests:no -include-traces:no -optimize', 
     358                        'type': 'bool', 
     359                }, 
     360                { 
     361                        'name': 'verbosity', 
     362                        'synonyms': ['verbose', 'v'], 
     363                        'type': 'int', 
     364                        'min': 0, 
     365                        'max': 5, 
     366                        'args': 'N', 
     367                        'description': 'Enable extra output from Cobra. Mostly useful for debugging Cobra and reporting problems. Values 0 - 5. Warning: Level 5 causes megabytes of output.', 
     368                }, 
     369                { 
     370                        'name': 'version', 
     371                        'description': 'Print just the version number.', # ([.versionString]).', 
     372                        'type': 'main', 
     373                }, 
     374        ] 
    6375 
    7376 
     
    34403                # period of time where this Cobra source represents an svn-post-RELEASE. 
    35404                return '0.8.0 post-release' 
    36  
    37         var _rawOptionSpecs = [ 
    38                 { 
    39                         'name': 'about', 
    40                         'description': 'Print the name, copyright, etc. but no usage.', 
    41                         'type': 'main', 
    42                 }, 
    43                 { 
    44                         'name': 'build-standard-library', 
    45                         'synonyms': ['bsl'], 
    46                         'description': 'Builds the standard library.', 
    47                         'type': 'main', 
    48                         'developer-only': true, 
    49                 }, 
    50                 { 
    51                         'name': 'compile', 
    52                         'synonyms': ['c'], 
    53                         'description': 'Compile the library (to DLL) or the program (to EXE) without running the code.', 
    54                         'type': 'main', 
    55                 }, 
    56                 { 
    57                         'name': 'color', 
    58                         'type': 'bool', 
    59                         'description': 'Colorizes the output of error messages and the messages "Compilation failed" and "Compilation succeeded" (as red, red and blue).', 
    60                 }, 
    61                 { 
    62                         'name': 'contracts', 
    63                         'description': 'Control treatment of code generation for contracts.', 
    64                         'type': 'menu', 
    65                         'choices': ['none', 'inline', 'methods'], 
    66                         'args': 'none|inline|methods', 
    67                         'default': 'inline', 
    68                 }, 
    69                 { 
    70                         'name': 'debug', 
    71                         'synonyms': ['d'], 
    72                         'type': 'string', 
    73                         'description': 'Turn on system debugging information. The value 1 implies full, which enables attaching a debugger to a running program. Turning on implies -debugging-tips:no.', 
    74                         'args': '0|1|pdbonly|full' 
    75                 }, 
    76                 { 
    77                         'name': 'debugging-tips', 
    78                         'description': 'Display debugging tips when an unhandled exception occurs. Overridden by -exception-report.', 
    79                         'type': 'bool', 
    80                         'default': 'yes', 
    81                 }, 
    82                 { 
    83                         'name': 'delay-sign', 
    84                         'type': 'bool', 
    85                         'description': 'Delay-sign the assembly using only the public portion of the strong name key.', 
    86                 }, 
    87                 { 
    88                         'name': 'detailed-stack-trace', 
    89                         'synonyms': ['dst'], 
    90                         'type': 'bool', 
    91                         'description': 'Enable a detailed stack trace which gives great postmortem information for uncaught exceptions, but slows execution. Works in combination with -exception-report.', 
    92                 }, 
    93                 { 
    94                         'name': 'embed-run-time', 
    95                         'synonyms': ['ert'], 
    96                         'type': 'bool', 
    97                         'default': 'no', 
    98                         'description': 'Embed the Cobra run-time support code (approx. 80KB) in the assembly so that no reference to an external Cobra.Lang.dll is required. If set to "no" then you should copy Cobra.Lang.dll to your current directory and also notice faster compilation time.', 
    99                 }, 
    100                 { 
    101                         'name': 'exception-report', 
    102                         'synonyms': ['exc-rpt', 'er'], 
    103                         'type': 'bool', 
    104                         'description': 'Turn on an informative HTML report that will be generated if the program throws an uncaught exception.', 
    105                 }, 
    106                 { 
    107                         'name': 'files', 
    108                         'isAccumulator': true, 
    109                         'description': 'Specify the files for Cobra to process in a separate text file. One file per line; # comments and blank lines are ignored.', 
    110                         'args': 'filename', 
    111                 }, 
    112                 { 
    113                         'name': 'editor', 
    114                         'description': 'Specify an editor and command line options to invoke if there is a compile-time error. Use underscore (_) for space in the specification. Can also set via COBRA_EDITOR environment variable (in which case spaces work fine).', 
    115                         'example': ['uedit32_FILE/LINE', 'mate_FILE_-l_LINE'], 
    116                         'args': 'editor_spec_with_FILE_LINE', 
    117                 }, 
    118                 { 
    119                         'name': 'extra-source', 
    120                         'type': 'string', 
    121                         'args': 'SOURCE', 
    122                         'description': 'Add extra source code to be compiled with the rest. Generally used only internally by the compiler.', 
    123                         'developer-only': true, 
    124                 }, 
    125                 { 
    126                         'name': 'document', 
    127                         'synonyms': ['doc'], 
    128                         'type': 'main', 
    129                         'description': 'Generate HTML docs for the Cobra source.', 
    130                 }, 
    131                 { 
    132                         'name': 'help', 
    133                         'synonyms': ['h'], 
    134                         'type': 'main', 
    135                         'description': 'Display this help message.', 
    136                 }, 
    137                 { 
    138                         'name': 'include-asserts', 
    139                         'type': 'bool', 
    140                         'default': 'yes', 
    141                         'description': 'Include assert statements in the program.', 
    142                 }, 
    143                 { 
    144                         'name': 'include-nil-checks', 
    145                         'type': 'bool', 
    146                         'default': 'yes', 
    147                         'description': 'Include checks on non-nilable class variables, method arguments and "to !" casts.', 
    148                 }, 
    149                 { 
    150                         'name': 'include-tests', 
    151                         'type': 'bool', 
    152                         'default': 'yes', 
    153                         'description': 'Includes unit tests for classes and members in the output assembly.', 
    154                 }, 
    155                 { 
    156                         'name': 'include-traces', 
    157                         'type': 'bool', 
    158                         'default': 'yes', 
    159                         'description': 'Includes trace statements in the output assembly.', 
    160                 }, 
    161                 { 
    162                         'name': 'keep-intermediate-files', 
    163                         'synonyms': ['kif'], 
    164                         'type': 'bool', 
    165                         'description': 'Keeps any intermediate files that Cobra generates, which are normally deleted. Example intermediate files are *.cobra.cs.', 
    166                 }, 
    167                 { 
    168                         'name': 'key-container', 
    169                         'type': 'string', 
    170                         'args': 'FILE', 
    171                         'description': 'Specify a strong name key container used to strongname the output assembly.', 
    172                 }, 
    173                 { 
    174                         'name': 'key-file', 
    175                         'type': 'string', 
    176                         'args': 'FILE', 
    177                         'description': 'Specify a strong name key file used to sign the output assembly.', 
    178                 }, 
    179                 { 
    180                         'name': 'library-directory', 
    181                         'synonyms': ['lib'], 
    182                         'type': 'string', 
    183                         'isAccumulator': true, 
    184                         'description': 'Specify additional directories to search in for references.', 
    185                         'args': 'PATH', 
    186                 }, 
    187                 { 
    188                         'name': 'number', 
    189                         'type': 'menu', 
    190                         'choices': ['decimal', 'float', 'float32', 'float64'], 
    191                         'args': 'decimal|float|float32|float64', 
    192                         'default': 'decimal', 
    193                         'description': "Set the real numeric type for both the 'number' type and fractional literals such as '1.0'.", 
    194                 }, 
    195                 { 
    196                         'name': 'optimize', 
    197                         'synonyms': ['o'], 
    198                         'type': 'bool', 
    199                         'description': 'Enable optimizations.', 
    200                 }, 
    201                 { 
    202                         'name': 'output-html', 
    203                         'type': 'bool', 
    204                         'description': "The command line's output will be in HTML.", 
    205                 }, 
    206                 { 
    207                         'name': 'pkg', 
    208                         'type': 'string', 
    209                         'isAccumulator': true, 
    210                         'description': 'References package via "pkg-config --libs". (Mono only.)', 
    211                         'args': 'NAME', 
    212                         'restriction': 'mono', 
    213                 }, 
    214                 { 
    215                         'name': 'reference', 
    216                         'synonyms': ['ref'],  
    217                         'isAccumulator': true, 
    218                         'description': 'Add a DLL reference.', 
    219                         'args': 'Some.dll', 
    220                 }, 
    221                 { 
    222                         'name': 'reveal-internal-exceptions', 
    223                         'description': 'When true, uncaught exceptions from the Cobra compiler itself are not caught and wrapped in error messages. This is useful when developing on the Cobra compiler itself. Set to true if the environment variable COBRA_IS_DEV_MACHINE.', 
    224                         'type': 'bool', 
    225                         'developer-only': true, 
    226                 }, 
    227 # TODO 
    228 #               { 
    229 #                       'name': 'reflect', 
    230 #                       'isAccumulator': true, 
    231 #                       'description': 'Display the type interface in Cobra syntax. Use its fully qualified name.', 
    232 #                       'args': ':Qualified.Type.Name', 
    233 #               }, 
    234                 { 
    235                         'name': 'run',          # this is a switch only    
    236                         'synonyms': ['r'],  
    237                         'description': 'Runs the Cobra program. This is the default behavior if specify any Cobra source files.', 
    238                         'type': 'main', 
    239                 }, 
    240                 { 
    241                         'name': 'run-args', 
    242                         'synonyms': ['-'],  # '--' 
    243                         'description': 'Remaining args are to be passed to executable.', 
    244                         'eg':          '-- arg1 arg2 arg3', 
    245