@@ -21,12 +21,14 @@ where the subcommands can be:
2121| _subcommand_ | _Description_ |
2222|:-------------|:-------------------------------------------------------------------------|
2323| install | followed by the _username/repository_, installs the specified repository |
24+ | require | followed by _username/repository_, examines the required version (see below) |
2425| query | followed by _username/repository_, returns all released versions of that package |
2526| check | followed by _username/repository_, evaluates whether the repository is installable |
2627| uninstall | followed by _package name_, uninstalls a package |
2728| search | followed by _keywords_, it searches the GitHub API for relevant packages or repositories |
2829| findfile | followed by a _keyword_, it searches Stata packages for files that include the keyword |
2930| list | lists the packages installed from GitHub and checkes if they have an update |
31+ | version | return the version of installed package or set a minimum required version |
3032
3133Description
3234-----------
@@ -60,7 +62,6 @@ searching for a keyword. The table shows the options accordingly:
6062| stable | installs the latest stable release. otherwise the main branch is installed |
6163| verson(_str_) | specifies a particular stable version (release tags) for the installation |
6264
63-
6465### __github search__ options:
6566
6667| _option_ | _Description_ |
@@ -98,11 +99,11 @@ install the latest development version of MarkDoc package
9899
99100install the latest stable version of MarkDoc package
100101
101- . github haghish/markdoc, stable
102+ . github install haghish/markdoc, stable
102103
103104install MarkDoc version 3.8.1 from GitHub (older version)
104105
105- . github haghish/markdoc, version("3.8.1")
106+ . github install haghish/markdoc, version("3.8.1")
106107
107108Uninstall MarkDoc repository
108109
@@ -130,12 +131,21 @@ search for a script files with the name _dy_
130131
131132 . github findfile dy
132133
134+ ### example of package management
135+
136+ list the installed packages
137+
138+ . github list
139+
140+ get the version of an installed packages, e.g. markdoc package
141+
142+ . github version markdoc
133143
134144### examples of searching the popular packages
135145
136- build the complete list of Stata packages on GiutHub
146+ search for Stata packages on GiutHub and save the search results in a data set
137147
138- . github list stata, language(all) in(all) all save(archive) append
148+ . github search stata, language(Stata) save(archive)
139149
140150Author
141151------
@@ -159,13 +169,13 @@ PLEASE NOTE
159169 intended to be used internally
160170*/
161171
162- * cap prog drop github
172+ cap prog drop github
163173prog define github
164174
165175 version 13
166176
167177 syntax anything, [stable Version(str) save(str) in(str) ///
168- language(str) all NET package(str) ///
178+ language(str) all NET package(str) require(str) ///
169179 /// the options below are not documented yet ///
170180 force created(str) pushed(str) debug reference(str) ///
171181 duration(numlist max= 1) perpage(numlist max= 1) ///
@@ -192,7 +202,45 @@ prog define github
192202 // Version //CHANGE THIS TO INFO?
193203 // ---------
194204 if " `1'" == " version" {
195- githubdb version, name(`anything')
205+ if missing(" `require'" ) {
206+ githubdb version, name(`anything')
207+ }
208+ else {
209+ qui githubdb version, name(`anything')
210+ local currentversion `r(version)'
211+ if " `r(version)'" ! = " `require'" {
212+ tokenize " `r(version)'" , parse(" ." )
213+ local currentversion `1'
214+ macro shift
215+ while ! missing(" `1'" ) {
216+ if " `1'" ! = " ." local sub `sub'`1'
217+ macro shift
218+ }
219+ local currentversion `currentversion'.`sub'
220+
221+ tokenize " `require'" , parse(" ." )
222+ local requiredversion `1'
223+ macro shift
224+ while ! missing(" `1'" ) {
225+ if " `1'" ! = " ." local sub `sub'`1'
226+ macro shift
227+ }
228+ local requiredversion `requiredversion'.`sub'
229+
230+ // return error if rcall is old
231+ if `requiredversion' > `currentversion' {
232+ display as err " Version `requiredversion' or newer is " ///
233+ " required"
234+ err 198
235+ }
236+ else {
237+ di as txt " version `r(version)' meets version `require' requirement"
238+ }
239+ }
240+ else {
241+ di as txt " version `require' is currently installed"
242+ }
243+ }
196244 exit
197245 }
198246
0 commit comments