-
Notifications
You must be signed in to change notification settings - Fork 40
/
githubfindall.ado
169 lines (134 loc) · 4.74 KB
/
githubfindall.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/***
version: 1.3
githubfindall
=============
a program to search for Stata packages on GitHub, Stata Journal,
SSC, and the web. ths program is executed by __github search__ command, with
the __net__ option and is not called on its own.
Syntax
------
> __githubfindall__ _keyword_
Description
-----------
__githubfindall__ is a general command for searching for Stata packages on variety of
web hosts, including GitHub, Stata, SSC, etc. The command wraps the Stata's
{help search} command and adds the results of __github search__ command from the
[github package](https://github.com/haghish/github).
In addition, the command shows the date of the last update of Stata modules on
SSC as well as GitHub, allowing the users to get the most recent version of the
package.
Example
-------
search for markdoc package on SSC and GitHub and show the last update
. githubfindall markdoc
Author
------
__E. F. Haghish__
Center for Medical Biometry and Medical Informatics
University of Freiburg, Germany
_and_
Department of Mathematics and Computer Science
University of Southern Denmark
haghish@imbi.uni-freiburg.de
- - -
This help file was dynamically produced by
[MarkDoc Literate Programming package](http://www.haghish.com/markdoc/)
***/
*cap prog drop githubfindall
program githubfindall
*syntax [anything] [, *]
syntax [anything] [, language(str) in(str) net local all]
// the search function prints nothing in results window in version 14
version 8
// avoid errors
capture log close findallpkg
// SYNTAX PRICESSING
// -----------------
if missing("`language'") local language Stata
if missing("`in'") local in name
// Create a log and save the search results
// -----------------------------------------------------------------------
tempfile log
qui log using "`log'", name(findallpkg)
if missing("`local'") & !missing("`net'") search `anything', all
if !missing("`local'") & missing("`net'") search `anything', local
if !missing("`local'") & !missing("`net'") search `anything'
*search `anything', local
github search `anything', in("`in'") language("`language'") `all'
qui log close findallpkg
//doedit "`log'"
// Edit the log, add useful information
// -----------------------------------------------------------------------
tempfile tmp pkg
tempname hitch knot hitch2
qui file open `hitch' using "`log'", read
qui file open `knot' using "`tmp'", write replace
file read `hitch' line
while r(eof) == 0 {
// Edit the log, add useful information
// -------------------------------------------------------------------
if missing("`local'") {
if `"`macval(line)'"' == "{title:Search of official help files, FAQs, Examples, SJs, and STBs}" {
file read `hitch' line
}
}
//get the versions from SSC
tokenize `"`macval(line)'"'
if `"`macval(1)'"' == "@net:describe" {
local len : di strlen(`"`macval(2)'"')
local name = substr(`"`macval(2)'"', 1, `len'-1)
if substr(`"`macval(3)'"', 1, 31) == "from(http://fmwww.bc.edu/RePEc/" {
cap local 3 = substr(`"`macval(3)'"', 6, .)
cap tokenize `"`macval(3)'"', parse(")")
cap qui copy "`1'/`name'.pkg" "`pkg'", replace
cap qui file open `hitch2' using "`pkg'", read
cap file read `hitch2' preline
while r(eof) == 0 {
if substr(`"`macval(preline)'"', 1, 20) == "d Distribution-Date:" {
cap local date = substr(`"`macval(preline)'"', 21, .)
cap local year = substr("`date'", 1,4)
cap local month = substr("`date'", 5,2)
cap local day = substr("`date'", 7,2)
cap local updated "`year'-`month'-`day'"
*if !missing("`updated'") {
*file write `knot' "{smcl}" _n ///
*`"{it:(updated on `updated'})"' _n ///
*"{s6hlp}" _n
*}
}
file read `hitch2' preline
}
file close `hitch2'
}
macro drop name
}
if `"`macval(line)'"' == "(end of search)" {
local line "Web resources from GitHub"
file write `knot' `"{smcl}"' _n
file write `knot' `"{title:`macval(line)'}"' _n
*file write `knot' "(contacting https://github.com)"
file read `hitch' line
}
else {
if missing("`updated'") {
file write `knot' `"`macval(line)'"' _n
}
else {
*capture tokenize `"`macval(line)'"' , parse(")!")
*di as err "`1'"
local length = strlen("`name'")
local col = 112+`length'
file write `knot' `"`macval(line)'"' _col(`col') `"(updated on `updated')"' _n
local updated
}
file read `hitch' line
}
}
file close `knot'
// View the results
// -----------------------------------------------------------------------
copy "`tmp'" `"`anything'"', replace
view "`anything'", smcl
capture erase "`anything'"
end
*markdoc githubfindall.ado , export(sthlp) replace build