summaryrefslogtreecommitdiff
path: root/scripts/cargo.pl
blob: 54d716e47a75e8e1270ae3428489a2400f2ce56c (plain) (blame)
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
#!/usr/bin/perl

use strict;
use warnings;
use feature qw(:5.22);

open my $cargo, '<', $ARGV[0] or die "can't open $ARGV[0]: $!\n";
my $data = '';
# This block reads in the entire file.
{
	local $/;
	$data = <$cargo>;
}

my $name = '';
my %cargo = ();
my @lines = split /\r?\n/, $data;

# Parse the file; we just want the name and version.
foreach my $line (@lines) {
	if ($line =~ /^name = "(.*?)"$/) {
		$name = $1;
	} elsif ($line =~ /^version = "(.*?)"$/) {
		$cargo{$name} = $1;
	}
}

open my $file, '>', 'crates.txt' or die "can't open output file: $!\n";
# Print the data we pulled out above to a file.
foreach my $pkg (keys %cargo) {
	say $file $pkg . ' ' . $cargo{$pkg};
}