Tcl Library Source Code

Check-in [487e9d220e]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Allow parse_args-style comments
Timelines: family | ancestors | descendants | both | amg-argparse
Files: files | file ages | folders
SHA3-256:487e9d220e31c91f7b4102e5d042e884dd3560c54d1ffc718fa1881fd6044354
User & Date: andy 2019-04-17 06:45:16
Context
2019-04-17
06:47
Begin writing documentation Leaf check-in: b40a9f709a user: andy tags: amg-argparse
06:45
Allow parse_args-style comments check-in: 487e9d220e user: andy tags: amg-argparse
2019-04-15
03:44
Import argparse version 0.4 which adds the ability to put overall options directly in the parameter definition list, a feature needed by the latest version of pipeline check-in: 50fdc84e6c user: andy tags: amg-argparse
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/argparse/argparse.tcl.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
...
288
289
290
291
292
293
294
295

296

297
298
299
300
301
302
303
#
# Feature-heavy argument parsing package
#
# Copyright (C) 2019 Andy Goth <andrew.m.goth@gmail.com>
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
package require Tcl 8.6
package provide argparse 0.4

# argparse --
# Parses an argument list according to a definition list.  The result may be
# stored into caller variables or returned as a dict.
#
# The [argparse] command accepts the following switches:
#
................................................................................
# -require LIST  If element is present, other elements that must be present
# -forbid LIST   If element is present, other elements that must not be present
# -imply LIST    If element is present, extra switch arguments; requires -switch
# -reciprocal    This element's -require is reciprocal; requires -require
# -validate DEF  Name of validation expression, or inline validation definition
# -enum DEF      Name of enumeration list, or inline enumeration definition
#
# As a special case, a definition list element may be the single character "#",
# which will cause the following element to be completely ignored.  This may be

# used to place comments directly within the definition list.
#
# If neither -switch nor -parameter are used, a shorthand form is permitted.  If
# the name is preceded by "-", it is a switch; otherwise, it is a parameter.  An
# alias may be written after "-", then followed by "|" and the switch name.  The
# element name may be followed by any number of flag characters:
#
# "="            Same as -argument; only valid for switches
................................................................................
            # Convert any definition list elements named empty string to instead
            # be overall switches, and arrange to reparse those switches.  Also,
            # remove inline comments from the definition list.
            set args {}
            set reparse {}
            set i -1
            foreach elem $definition[set definition {}] {
                if {$elem eq "#"} {

                    set comment {}

                } elseif {[info exists comment]} {
                    unset comment
                } elseif {[lindex $elem 0] eq {}} {
                    lappend args {*}[lrange $elem 1 end]
                } else {
                    lappend definition $elem
                }







|







 







|
|
>
|







 







|
>
|
>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#
# Feature-heavy argument parsing package
#
# Copyright (C) 2019 Andy Goth <andrew.m.goth@gmail.com>
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
package require Tcl 8.6
package provide argparse 0.5

# argparse --
# Parses an argument list according to a definition list.  The result may be
# stored into caller variables or returned as a dict.
#
# The [argparse] command accepts the following switches:
#
................................................................................
# -require LIST  If element is present, other elements that must be present
# -forbid LIST   If element is present, other elements that must not be present
# -imply LIST    If element is present, extra switch arguments; requires -switch
# -reciprocal    This element's -require is reciprocal; requires -require
# -validate DEF  Name of validation expression, or inline validation definition
# -enum DEF      Name of enumeration list, or inline enumeration definition
#
# If the first (possibly only) word of a definition list element is the single
# character "#", the element is ignored.  If the definition list element is only
# one word long, the following element is ignored as well.  This may be used to
# place comments directly within the definition list.
#
# If neither -switch nor -parameter are used, a shorthand form is permitted.  If
# the name is preceded by "-", it is a switch; otherwise, it is a parameter.  An
# alias may be written after "-", then followed by "|" and the switch name.  The
# element name may be followed by any number of flag characters:
#
# "="            Same as -argument; only valid for switches
................................................................................
            # Convert any definition list elements named empty string to instead
            # be overall switches, and arrange to reparse those switches.  Also,
            # remove inline comments from the definition list.
            set args {}
            set reparse {}
            set i -1
            foreach elem $definition[set definition {}] {
                if {[lindex $elem 0] eq "#"} {
                    if {[llength $elem] == 1} {
                        set comment {}
                    }
                } elseif {[info exists comment]} {
                    unset comment
                } elseif {[lindex $elem 0] eq {}} {
                    lappend args {*}[lrange $elem 1 end]
                } else {
                    lappend definition $elem
                }

Changes to modules/argparse/pkgIndex.tcl.

1
package ifneeded argparse 0.4 [list source [file join $dir argparse.tcl]]
|
1
package ifneeded argparse 0.5 [list source [file join $dir argparse.tcl]]