Skip to content

Commit 2d721a7

Browse files
committed
Repology 1.5.0
Add autodetection for Windows, selecting cholocatey. Add a configure script to make packaging much easier. Improve documentation in manual page and README.md
1 parent c73c12c commit 2d721a7

File tree

6 files changed

+216
-66
lines changed

6 files changed

+216
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
repology
22
repology.o
33
repology.core
4+
Makefile

Makefile

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,26 @@
11
repology
22
========
3-
`repology` is a command line interface for Repology.org.
4-
It is primarily designed for
5-
[OpenBSD](https://openbsd.org/),
6-
[FreeBSD](https://freebsd.org/),
7-
[NetBSD](https://netbsd.org/),
8-
and
9-
[macOS](https://apple.com/)
10-
developers, users, and port maintainers.
11-
12-
It is written in
3+
`repology` is a command line interface for
4+
[Repology.org](https://repology.org/)
5+
written in
136
[D](https://dlang.org/).
147

8+
`repology` will attempt to autodetect your operating system for
9+
selecting a repository when `--repo` is not specified. This
10+
autodetection works for the BSDs, macOS, and Windows.
11+
1512
Building
1613
--------
17-
If you are using
18-
[DMD](https://wiki.dlang.org/DMD):
1914
```sh
15+
$ ./configure
2016
$ make
2117
$ sudo make install
2218
```
2319

24-
If you are using
25-
[LDC](https://wiki.dlang.org/LDC):
26-
```sh
27-
$ make DMD=ldmd2
28-
$ sudo make install
29-
```
30-
31-
If you are using
32-
[GDC](https://wiki.dlang.org/GDC):
33-
```sh
34-
$ make DMD=gdc DFLAGS='-O2 -pipe -frelease -finline -o repology'
35-
$ sudo make install
36-
```
37-
3820
Usage examples
3921
--------------
40-
Get information on the Digital Mars D compiler from the default repository:
22+
Get information on the Digital Mars D compiler from your operating
23+
system's autodetected repository:
4124
* `repology dmd`
4225

4326
Get information on the Digital Mars D compiler from all repositories:

configure

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/bin/sh
2+
3+
# This configure script written by Brian Callahan <bcallah@openbsd.org>
4+
# and released into the Public Domain.
5+
6+
Makefile() {
7+
cat << EOF > Makefile
8+
# This Makefile automatically generated by configure.
9+
10+
BINDIR = $bindir
11+
MANDIR = $mandir
12+
13+
DMD = $dmd
14+
DFLAGS = $dflags
15+
16+
PROG = repology
17+
18+
all:
19+
\${DMD} \${DFLAGS} $oflag \${PROG}.d
20+
21+
install:
22+
install -c -s -m 755 \${PROG} \${DESTDIR}\${BINDIR}
23+
install -c -m 444 \${PROG}.1 \${DESTDIR}\${MANDIR}/man1
24+
25+
uninstall:
26+
rm -f \${BINDIR}/\${PROG} \${MANDIR}/man1/\${PROG}.1
27+
28+
test:
29+
@echo No tests.
30+
31+
clean:
32+
rm -f \${PROG} \${PROG}.o \${PROG}.core
33+
34+
distclean: clean
35+
rm -f Makefile
36+
EOF
37+
}
38+
39+
dmdcheck() {
40+
for compiler in "$DMD" ldc2 gdc dmd ; do
41+
cat << EOF > conftest.d
42+
void main(){}
43+
EOF
44+
($compiler --version | grep -q "LDC - the LLVM D compiler") > /dev/null 2>&1
45+
if [ $? -eq 0 ] ; then
46+
is="ldc"
47+
else
48+
($compiler --version | grep -q "Free Software Foundation") > /dev/null 2>&1
49+
if [ $? -eq 0 ] ; then
50+
is="gdc"
51+
else
52+
is="dmd"
53+
fi
54+
fi
55+
if [ $specifieddflags -eq 0 ] ; then
56+
case "$is" in
57+
"dmd")
58+
dflags="-O -release -inline"
59+
;;
60+
"gdc")
61+
dflags="-O2 -pipe -frelease -finline"
62+
oflag="-o repology"
63+
;;
64+
"ldc")
65+
dflags="-O -release"
66+
;;
67+
esac
68+
fi
69+
if [ "x$is" = "xgdc" ] ; then
70+
$compiler $dflags -o conftest conftest.d > /dev/null 2>&1
71+
else
72+
$compiler $dflags conftest.d > /dev/null 2>&1
73+
fi
74+
if [ $? -eq 0 ] ; then
75+
rm -f conftest conftest.o conftest.d
76+
dmd="$compiler"
77+
return 0
78+
else
79+
rm -f conftest conftest.o conftest.d
80+
fi
81+
done
82+
return 1
83+
}
84+
85+
# Option variables
86+
if [ ! -z "$PREFIX" ] ; then
87+
prefix="$PREFIX"
88+
else
89+
prefix="/usr/local"
90+
fi
91+
92+
bindirset=0
93+
mandirset=0
94+
specifieddflags=0
95+
bindir="$prefix/bin"
96+
mandir="$prefix/share/man"
97+
98+
# Options
99+
for opt
100+
do
101+
case "$opt" in
102+
--prefix=*)
103+
prefix=${opt#*=}
104+
if [ $bindirset -eq 0 ] ; then
105+
bindir="$prefix/bin"
106+
fi
107+
if [ $mandirset -eq 0 ] ; then
108+
mandir="$prefix/share/man"
109+
fi
110+
;;
111+
--bindir=*)
112+
bindir=${opt#*=}
113+
bindirset=1
114+
;;
115+
--mandir=*)
116+
mandir=${opt#*=}
117+
mandirset=1
118+
;;
119+
--dmd=*)
120+
DMD=${opt#*=}
121+
;;
122+
--dflags=*)
123+
dflags=${opt#*=}
124+
specifieddflags=1
125+
;;
126+
--help|-h)
127+
echo "Usage: configure [options]"
128+
echo ""
129+
echo "Options:"
130+
printf " --help or -h "
131+
echo "Display this help message"
132+
printf " --prefix=PREFIX "
133+
echo "Top level install directory is PREFIX [$prefix]"
134+
printf " --bindir=BINDIR "
135+
echo "Install executable to BINDIR [$bindir]"
136+
printf " --mandir=MANDIR "
137+
echo "Install manual pages to MANDIR [$mandir]"
138+
printf " --dmd=DMD "
139+
echo "Use specified D compiler [default=autodetect]"
140+
printf " --dflags=DFLAGS "
141+
echo "Use specified DFLAGS [default=autodetect]"
142+
exit 1
143+
;;
144+
*)
145+
;;
146+
esac
147+
done
148+
149+
printf "checking for D compiler... "
150+
dmdcheck
151+
if [ $? -ne 0 ] ; then
152+
echo "not found"
153+
echo "error: Please install a D compiler and re-run configure"
154+
exit 1
155+
else
156+
echo "$dmd"
157+
fi
158+
159+
printf "creating Makefile... "
160+
Makefile
161+
echo "done"

repology.1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1616
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1717
.\"
18-
.Dd December 21, 2024
18+
.Dd December 23, 2024
1919
.Dt REPOLOGY 1
2020
.Os
2121
.Sh NAME
@@ -37,6 +37,11 @@ selects an appropriate repository based on your operating system:
3737
.Dl macOS Ar homebrew
3838
.Dl NetBSD Ar pkgsrc_current
3939
.Dl OpenBSD Ar openbsd
40+
.Dl Windows Ar chocolatey
41+
.Pp
42+
Linux users will need to specify their repository with the
43+
.Fl -repo
44+
flag.
4045
.Pp
4146
.Nm
4247
returns information in the following format:
@@ -136,11 +141,12 @@ The package is up to date.
136141
.It Red
137142
The package is outdated.
138143
.It Cyan
139-
The package is either a development version or unique to this repo.
144+
The package is either a development version, unique to this repo,
145+
or a rolling release.
140146
.It Yellow
141147
The package is a legacy version.
142148
.It Magenta
143-
The package has no known versioning scheme or is a rolling release.
149+
The package has no known versioning scheme.
144150
.It Blue
145151
The package version is incorrect, untrusted, or otherwise ignored.
146152
.El
@@ -172,9 +178,12 @@ Get up to 200 packages maintained by ports@openbsd.org,
172178
starting with coreutils:
173179
.Pp
174180
.Dl repology --maintainer ports@openbsd.org --begin coreutils
175-
.Sh CAVEATS
176-
Not all repositories may contain all information.
181+
.Sh SEE ALSO
182+
The repology API documentation can be found at
183+
.Lk https://repology.org/api/v1 .
177184
.Sh AUTHORS
178185
.Nm
179186
was written by
180187
.An Brian Callahan Aq Mt bcallah@openbsd.org .
188+
.Sh CAVEATS
189+
Not all repositories may contain all information.

repology.d

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ struct Options
4545
vers;
4646
}
4747

48-
void main(string[] args)
48+
int main(string[] args)
4949
{
5050
Options options;
5151
JSONValue json;
5252
string[] pkgs;
5353
string uri = "https://repology.org/api/v1/project";
5454
string[string] queryParts = null;
5555

56-
version (FreeBSD) options.repo = "freebsd";
56+
version (OpenBSD) options.repo = "openbsd";
57+
else version (FreeBSD) options.repo = "freebsd";
5758
else version (NetBSD) options.repo = "pkgsrc_current";
5859
else version (OSX) options.repo = "homebrew";
59-
else options.repo = "openbsd";
60+
else version (Windows) options.repo = "chocolatey";
61+
else
62+
{
63+
stderr.writeln("repology: specify your repo with the --repo flag");
64+
return 1;
65+
}
6066

6167
auto opts = getopt(
6268
args,
@@ -83,12 +89,12 @@ void main(string[] args)
8389
if (opts.helpWanted) {
8490
defaultGetoptPrinter("usage: repology [options] [package ...]",
8591
opts.options);
86-
return;
92+
return 1;
8793
}
8894

8995
if (options.vers) {
90-
writeln("1.4.0 (21 Dec 2024)");
91-
return;
96+
writeln("1.5.0 (23 Dec 2024)");
97+
return 1;
9298
}
9399

94100
if (options.repo == "pkgsrc")
@@ -134,14 +140,26 @@ void main(string[] args)
134140
if (!pkg.empty)
135141
writeln(pkg);
136142
}
143+
144+
return 0;
137145
}
138146

139147
string[] process(JSONValue json, Options options)
140148
{
141149
JSONValue[] j;
142150
string[] info;
143151
string latest;
144-
bool havelatest;
152+
bool hasmaintainer, havelatest;
153+
154+
switch (options.repo) {
155+
case "freebsd":
156+
case "openbsd":
157+
case "pkgsrc_current":
158+
hasmaintainer = true;
159+
break;
160+
default:
161+
hasmaintainer = false;
162+
}
145163

146164
foreach (obj; json.array) {
147165
switch (obj["status"].str) {
@@ -188,7 +206,10 @@ string[] process(JSONValue json, Options options)
188206
if (!options.all) {
189207
if (options.sort_package)
190208
tmp ~= obj["binname"].str ~ " ";
191-
tmp ~= obj["srcname"].str ~ " ";
209+
if (options.repo == "chocolatey")
210+
tmp ~= obj["binname"].str ~ " ";
211+
else
212+
tmp ~= obj["srcname"].str ~ " ";
192213
}
193214
string color;
194215
switch (obj["status"].str) {
@@ -218,7 +239,7 @@ string[] process(JSONValue json, Options options)
218239
color = "32";
219240
}
220241
string ver = "\033[" ~ color ~ "m" ~ obj["version"].str ~ "\033[0m";
221-
if (!options.all && options.repo != "homebrew") {
242+
if (!options.all && hasmaintainer) {
222243
string maintainer = "";
223244
auto maintainers = obj["maintainers"].array;
224245
foreach (i; 0 .. maintainers.length) {

0 commit comments

Comments
 (0)