Fossil Wrapper

Check-in [5912961aa5]
Login

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

Overview
Comment:Provide optional docstring support in interceptor definitions (addresses [1f4a2dbd11]).
Timelines: family | ancestors | interceptor-docstrings
Files: files | file ages | folders
SHA1: 5912961aa5e443ebdbdf874f242a1a55804244c8
User & Date: marc 2013-01-17 15:01:15
References
2013-01-17
15:06 Ticket [1f4a2dbd11] Interceptors should have optional doc strings. status still Open with 5 other changes artifact: 217275362f user: marc
Context
2013-01-17
15:01
Provide optional docstring support in interceptor definitions (addresses [1f4a2dbd11]). Leaf check-in: 5912961aa5 user: marc tags: interceptor-docstrings
05:20
Update copyright year and include 'LICENSE' in 'fsl'. Leaf check-in: 06a31756cc user: marc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

19
20
21
22
23
24
25

26
27
28
29
30
31
32
...
153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
...
283
284
285
286
287
288
289




290
291
292
293
294
295
296

# --( Aliases and Filters )---------------------------------------------

namespace eval config {
    set aliases {}
    set filters {};             # registered filters
    set commands {};            # registered interceptors


    proc init {filename} {
        if {[file exists $filename]} {
            set conf [read [open $filename]]
        } else {
            set conf [unindent_script $config::defaults]
            puts "(Creating $filename)"
................................................................................
#
# - If an interceptor returns an empty list, the wrapper is expected
#   to exit without calling Fossil, thereby fully intercepting the
#   query. Otherwise, it acts as a pre-processor: the returned list is
#   treated as a revised parameter list and will be supplied to
#   `fossil'.

proc interceptor {command_spec body} {
    set fn [list {params} $body [uplevel 1 {namespace current}]]
    foreach command [triggers_for $command_spec] {
        dict set config::commands $command $fn

    }
}

proc intercept {params} {
    set command [first $params]
    if {[interceptor? $command]} {
        return [apply [dict get $config::commands $command] $params]
................................................................................
interceptor he:help {
    # Wrap builtin help command by expanding its argument list. This
    # allows us provide help on aliased commands transparently. When
    # the expanded command is an interceptor, simply print its body.
    set expansion [expand [lrange $params 1 end] 1]
    set command   [first $expansion]
    if {![prefix? $command "help"] && [interceptor? $command]} {




        puts "'$command' is an interceptor defined as follows:"
        puts [lindex [dict get $config::commands $command] 1]
    } else {
        concat help $expansion
    }
}








>







 







|


|
>







 







>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

# --( Aliases and Filters )---------------------------------------------

namespace eval config {
    set aliases {}
    set filters {};             # registered filters
    set commands {};            # registered interceptors
    set docstring {};           # docstrings for registered interceptors

    proc init {filename} {
        if {[file exists $filename]} {
            set conf [read [open $filename]]
        } else {
            set conf [unindent_script $config::defaults]
            puts "(Creating $filename)"
................................................................................
#
# - If an interceptor returns an empty list, the wrapper is expected
#   to exit without calling Fossil, thereby fully intercepting the
#   query. Otherwise, it acts as a pre-processor: the returned list is
#   treated as a revised parameter list and will be supplied to
#   `fossil'.

proc interceptor {command_spec body {docstring ""}} {
    set fn [list {params} $body [uplevel 1 {namespace current}]]
    foreach command [triggers_for $command_spec] {
        dict set config::commands  $command $fn
        dict set config::docstring $command $docstring
    }
}

proc intercept {params} {
    set command [first $params]
    if {[interceptor? $command]} {
        return [apply [dict get $config::commands $command] $params]
................................................................................
interceptor he:help {
    # Wrap builtin help command by expanding its argument list. This
    # allows us provide help on aliased commands transparently. When
    # the expanded command is an interceptor, simply print its body.
    set expansion [expand [lrange $params 1 end] 1]
    set command   [first $expansion]
    if {![prefix? $command "help"] && [interceptor? $command]} {
        set docstring [dict get $config::docstring $command]
        if {$docstring != ""} {
            return [puts [unindent_script $docstring]]
        }
        puts "'$command' is an interceptor defined as follows:"
        puts [lindex [dict get $config::commands $command] 1]
    } else {
        concat help $expansion
    }
}