Fossil SCM
Add script to automate updating common command list in man page, and use it to update the man page
Commit
42d6c86fa1f2077218693f952a5a4a2dc539e072
Parent
def9af43a392123…
2 files changed
+19
-19
+68
M
fossil.1
+19
-19
| --- fossil.1 | ||
| +++ fossil.1 | ||
| @@ -14,29 +14,29 @@ | ||
| 14 | 14 | Fossil is a distributed version control system (DVCS) with built-in |
| 15 | 15 | wiki, ticket tracker, CGI/http interface, and http server. |
| 16 | 16 | |
| 17 | 17 | .SH Common COMMANDs: |
| 18 | 18 | |
| 19 | -add clean import pull stash | |
| 20 | -.br | |
| 21 | -addremove clone info purge status | |
| 22 | -.br | |
| 23 | -all commit init push sync | |
| 24 | -.br | |
| 25 | -annotate diff json rebuild tag | |
| 26 | -.br | |
| 27 | -bisect export ls remote-url timeline | |
| 28 | -.br | |
| 29 | -blame extras merge revert ui | |
| 30 | -.br | |
| 31 | -branch finfo mv rm undo | |
| 32 | -.br | |
| 33 | -bundle fusefs open rss unpublish | |
| 34 | -.br | |
| 35 | -cat gdiff praise settings update | |
| 36 | -.br | |
| 37 | -changes help publish sqlite3 version | |
| 19 | +add changes gdiff publish status | |
| 20 | +.br | |
| 21 | +addremove clean help pull sync | |
| 22 | +.br | |
| 23 | +all clone import push tag | |
| 24 | +.br | |
| 25 | +amend commit info rebuild timeline | |
| 26 | +.br | |
| 27 | +annotate delete init remote-url ui | |
| 28 | +.br | |
| 29 | +bisect diff ls revert undo | |
| 30 | +.br | |
| 31 | +blame export merge rm unpublished | |
| 32 | +.br | |
| 33 | +branch extras mv settings unversioned | |
| 34 | +.br | |
| 35 | +bundle finfo open sqlite3 update | |
| 36 | +.br | |
| 37 | +cat fusefs praise stash version | |
| 38 | 38 | |
| 39 | 39 | .SH FEATURES |
| 40 | 40 | |
| 41 | 41 | Features as described on the fossil home page. |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | ADDED tools/man_page_command_list.tcl |
| --- fossil.1 | |
| +++ fossil.1 | |
| @@ -14,29 +14,29 @@ | |
| 14 | Fossil is a distributed version control system (DVCS) with built-in |
| 15 | wiki, ticket tracker, CGI/http interface, and http server. |
| 16 | |
| 17 | .SH Common COMMANDs: |
| 18 | |
| 19 | add clean import pull stash |
| 20 | .br |
| 21 | addremove clone info purge status |
| 22 | .br |
| 23 | all commit init push sync |
| 24 | .br |
| 25 | annotate diff json rebuild tag |
| 26 | .br |
| 27 | bisect export ls remote-url timeline |
| 28 | .br |
| 29 | blame extras merge revert ui |
| 30 | .br |
| 31 | branch finfo mv rm undo |
| 32 | .br |
| 33 | bundle fusefs open rss unpublish |
| 34 | .br |
| 35 | cat gdiff praise settings update |
| 36 | .br |
| 37 | changes help publish sqlite3 version |
| 38 | |
| 39 | .SH FEATURES |
| 40 | |
| 41 | Features as described on the fossil home page. |
| 42 | |
| 43 | |
| 44 | DDED tools/man_page_command_list.tcl |
| --- fossil.1 | |
| +++ fossil.1 | |
| @@ -14,29 +14,29 @@ | |
| 14 | Fossil is a distributed version control system (DVCS) with built-in |
| 15 | wiki, ticket tracker, CGI/http interface, and http server. |
| 16 | |
| 17 | .SH Common COMMANDs: |
| 18 | |
| 19 | add changes gdiff publish status |
| 20 | .br |
| 21 | addremove clean help pull sync |
| 22 | .br |
| 23 | all clone import push tag |
| 24 | .br |
| 25 | amend commit info rebuild timeline |
| 26 | .br |
| 27 | annotate delete init remote-url ui |
| 28 | .br |
| 29 | bisect diff ls revert undo |
| 30 | .br |
| 31 | blame export merge rm unpublished |
| 32 | .br |
| 33 | branch extras mv settings unversioned |
| 34 | .br |
| 35 | bundle finfo open sqlite3 update |
| 36 | .br |
| 37 | cat fusefs praise stash version |
| 38 | |
| 39 | .SH FEATURES |
| 40 | |
| 41 | Features as described on the fossil home page. |
| 42 | |
| 43 | |
| 44 | DDED tools/man_page_command_list.tcl |
| --- a/tools/man_page_command_list.tcl | ||
| +++ b/tools/man_page_command_list.tcl | ||
| @@ -0,0 +1,68 @@ | ||
| 1 | +#!/usr/bin/env tclsh | |
| 2 | +# command_mannv tclsh | |
| 3 | +# man_page_command_list.tcl - generates common command list for fossil.1 | |
| 4 | + | |
| 5 | +# Tunable configuration. | |
| 6 | +set columns 5 | |
| 7 | +set width 15 | |
| 8 | + | |
| 9 | +# The only supported command-line argument is the optional output filename. | |
| 10 | +if {[llength $argv] == 1} { | |
| 11 | + set file [lindex $argv 0] | |
| 12 | +} | |
| 13 | + | |
| 14 | +# Get list of common commands. | |
| 15 | +set commands [exec fossil common commands:.*\n} $commands {} commands | |
| 16 | +regsub -nocase {\nthis is fossil version.*} $commands {} commands | |
| 17 | +regsub -all {\s+} $commands " " commands | |
| 18 | +set commands [lsort $commands] | |
| 19 | + | |
| 20 | +# Compute number of rows. | |
| 21 | +set rows [expr {([llength $commands] + $columns - 1) / $columns}] | |
| 22 | + | |
| 23 | +# Generate text one line at a time. | |
| 24 | +set text {} | |
| 25 | +for {set row 0} {$row < $rows} {incr row} { | |
| 26 | + # Separate rows with line break. | |
| 27 | + if {$row} { | |
| 28 | + append text .br\n | |
| 29 | + } | |
| 30 | + | |
| 31 | + # Generate the row of commands. | |
| 32 | + for {set col 0} {$col < $columns} {incr col} { | |
| 33 | + set i [expr {$col * $rows + $row}] | |
| 34 | + if {$i < [llength $commands]} { | |
| 35 | + append text [format %-*s $width [lindex $commands $i]] | |
| 36 | + } | |
| 37 | + } | |
| 38 | + append text \n | |
| 39 | +} | |
| 40 | + | |
| 41 | +# Strip trailing whitespace from each line. | |
| 42 | +regsub -all {\s+\n} $text \n text | |
| 43 | + | |
| 44 | +# Output text. | |
| 45 | +if {[info exists file]} { | |
| 46 | + # If a filename was specified, read the file for use as a template. | |
| 47 | + set chan [open $file] | |
| 48 | + set data [read $chan] | |
| 49 | + close $chan | |
| 50 | + | |
| 51 | + # Locate the part of the file to replace. | |
| 52 | + if {[regexp -indices {\n\.SH Common COMMANDs:\n\n(.*?)\n\.SH} $data\ | |
| 53 | + _ range]} { | |
| 54 | + # If found, replace with the updated command list. | |
| 55 | + set chan [open $file w] | |
| 56 | + puts -nonewline $chan [string replace $data\ | |
| 57 | + [lindex $range 0] [lindex $range 1] $text] | |
| 58 | + close $chan | |
| 59 | + } else { | |
| 60 | + # If not found, abort. | |
| 61 | + error "could not find command list in man file \"$file\"" | |
| 62 | + } | |
| 63 | +} else { | |
| 64 | + # If no filename was specified, write to stdout. | |
| 65 | + puts $text | |
| 66 | +} | |
| 67 | + | |
| 68 | +# vim: set s |
| --- a/tools/man_page_command_list.tcl | |
| +++ b/tools/man_page_command_list.tcl | |
| @@ -0,0 +1,68 @@ | |
| --- a/tools/man_page_command_list.tcl | |
| +++ b/tools/man_page_command_list.tcl | |
| @@ -0,0 +1,68 @@ | |
| 1 | #!/usr/bin/env tclsh |
| 2 | # command_mannv tclsh |
| 3 | # man_page_command_list.tcl - generates common command list for fossil.1 |
| 4 | |
| 5 | # Tunable configuration. |
| 6 | set columns 5 |
| 7 | set width 15 |
| 8 | |
| 9 | # The only supported command-line argument is the optional output filename. |
| 10 | if {[llength $argv] == 1} { |
| 11 | set file [lindex $argv 0] |
| 12 | } |
| 13 | |
| 14 | # Get list of common commands. |
| 15 | set commands [exec fossil common commands:.*\n} $commands {} commands |
| 16 | regsub -nocase {\nthis is fossil version.*} $commands {} commands |
| 17 | regsub -all {\s+} $commands " " commands |
| 18 | set commands [lsort $commands] |
| 19 | |
| 20 | # Compute number of rows. |
| 21 | set rows [expr {([llength $commands] + $columns - 1) / $columns}] |
| 22 | |
| 23 | # Generate text one line at a time. |
| 24 | set text {} |
| 25 | for {set row 0} {$row < $rows} {incr row} { |
| 26 | # Separate rows with line break. |
| 27 | if {$row} { |
| 28 | append text .br\n |
| 29 | } |
| 30 | |
| 31 | # Generate the row of commands. |
| 32 | for {set col 0} {$col < $columns} {incr col} { |
| 33 | set i [expr {$col * $rows + $row}] |
| 34 | if {$i < [llength $commands]} { |
| 35 | append text [format %-*s $width [lindex $commands $i]] |
| 36 | } |
| 37 | } |
| 38 | append text \n |
| 39 | } |
| 40 | |
| 41 | # Strip trailing whitespace from each line. |
| 42 | regsub -all {\s+\n} $text \n text |
| 43 | |
| 44 | # Output text. |
| 45 | if {[info exists file]} { |
| 46 | # If a filename was specified, read the file for use as a template. |
| 47 | set chan [open $file] |
| 48 | set data [read $chan] |
| 49 | close $chan |
| 50 | |
| 51 | # Locate the part of the file to replace. |
| 52 | if {[regexp -indices {\n\.SH Common COMMANDs:\n\n(.*?)\n\.SH} $data\ |
| 53 | _ range]} { |
| 54 | # If found, replace with the updated command list. |
| 55 | set chan [open $file w] |
| 56 | puts -nonewline $chan [string replace $data\ |
| 57 | [lindex $range 0] [lindex $range 1] $text] |
| 58 | close $chan |
| 59 | } else { |
| 60 | # If not found, abort. |
| 61 | error "could not find command list in man file \"$file\"" |
| 62 | } |
| 63 | } else { |
| 64 | # If no filename was specified, write to stdout. |
| 65 | puts $text |
| 66 | } |
| 67 | |
| 68 | # vim: set s |