4
4
// (1) install golang
5
5
// (2) install bitcoin core, set it up to use regtest
6
6
// (3) run bitcoind
7
- // (4) change BITCOIN_PATH to actual bitcoin-cli directory path, change VERSION
8
- // (5) run this script with `go run generate.go` while being in contrib/doc-gen
9
- // (6) add the generated files to git
7
+ // (4) run this script with `go run generate.go` while being in contrib/doc-gen, and with bitcoin-cli in PATH
8
+ // (5) add the generated files to git
10
9
package main
11
10
12
11
import (
12
+ "encoding/json"
13
13
"fmt"
14
- "text/template"
15
14
"io"
16
15
"log"
17
16
"os"
18
17
"os/exec"
19
18
"strings"
19
+ "text/template"
20
20
)
21
21
22
- const BITCOIN_PATH = "/home/g/dev/bitcoind/bitcoin-0.16.0/bin/bitcoin-cli"
23
- const VERSION = "0.16.0"
22
+ const BITCOIN_COMMAND = "bitcoin-cli"
24
23
25
24
type Command struct {
26
25
Name string
@@ -41,7 +40,23 @@ type CommandData struct {
41
40
Permalink string
42
41
}
43
42
43
+ func getVersion () string {
44
+ allInfo := run ("getnetworkinfo" )
45
+ var f interface {}
46
+ err := json .Unmarshal ([]byte (allInfo ), & f )
47
+ if err != nil {
48
+ panic ("Cannot read network info as JSON" )
49
+ }
50
+ m := f .(map [string ]interface {})
51
+
52
+ numv := int (m ["version" ].(float64 ))
53
+ v := fmt .Sprintf ("%d.%d.%d" , numv / 1000000 , (numv / 10000 )% 100 , (numv / 100 )% 100 )
54
+ return v
55
+ }
56
+
44
57
func main () {
58
+ version := getVersion ()
59
+
45
60
first := run ("help" )
46
61
split := strings .Split (first , "\n " )
47
62
@@ -85,17 +100,17 @@ func main() {
85
100
86
101
for _ , group := range groups {
87
102
groupname := group .Name
88
- dirname := fmt .Sprintf ("../../_doc/en/%s/rpc/%s/" , VERSION , groupname )
103
+ dirname := fmt .Sprintf ("../../_doc/en/%s/rpc/%s/" , version , groupname )
89
104
err := os .MkdirAll (dirname , 0777 )
90
105
if err != nil {
91
106
log .Fatalf ("Cannot make directory %s: %s" , dirname , err .Error ())
92
107
}
93
108
for _ , command := range group .Commands {
94
109
name := command .Name
95
110
address := fmt .Sprintf ("%s%s.html" , dirname , name )
96
- permalink := fmt .Sprintf ("en/doc/%s/rpc/%s/%s/" , VERSION , groupname , name )
111
+ permalink := fmt .Sprintf ("en/doc/%s/rpc/%s/%s/" , version , groupname , name )
97
112
err = tmpl .Execute (open (address ), CommandData {
98
- Version : VERSION ,
113
+ Version : version ,
99
114
Name : name ,
100
115
Description : command .Description ,
101
116
Group : groupname ,
@@ -105,10 +120,10 @@ func main() {
105
120
log .Fatalf ("Cannot make command file %s: %s" , name , err .Error ())
106
121
}
107
122
}
108
- address := fmt .Sprintf ("../../_doc/en/%s/rpc/index.html" , VERSION )
109
- permalink := fmt .Sprintf ("en/doc/%s/rpc/" , VERSION )
123
+ address := fmt .Sprintf ("../../_doc/en/%s/rpc/index.html" , version )
124
+ permalink := fmt .Sprintf ("en/doc/%s/rpc/" , version )
110
125
err = tmpl .Execute (open (address ), CommandData {
111
- Version : VERSION ,
126
+ Version : version ,
112
127
Name : "rpcindex" ,
113
128
Description : "" ,
114
129
Group : "index" ,
@@ -118,10 +133,10 @@ func main() {
118
133
log .Fatalf ("Cannot make index file: %s" , err .Error ())
119
134
}
120
135
121
- address = fmt .Sprintf ("../../_doc/en/%s/index.html" , VERSION )
122
- permalink = fmt .Sprintf ("en/doc/%s/" , VERSION )
136
+ address = fmt .Sprintf ("../../_doc/en/%s/index.html" , version )
137
+ permalink = fmt .Sprintf ("en/doc/%s/" , version )
123
138
err = tmpl .Execute (open (address ), CommandData {
124
- Version : VERSION ,
139
+ Version : version ,
125
140
Name : "index" ,
126
141
Description : "" ,
127
142
Group : "index" ,
@@ -143,7 +158,7 @@ func open(path string) io.Writer {
143
158
}
144
159
145
160
func run (args ... string ) string {
146
- out , err := exec .Command (BITCOIN_PATH , args ... ).CombinedOutput ()
161
+ out , err := exec .Command (BITCOIN_COMMAND , args ... ).CombinedOutput ()
147
162
if err != nil {
148
163
log .Fatalf ("Cannot run bitcoin-cli: %s, is bitcoind running?" , err .Error ())
149
164
}
0 commit comments