Skip to content

Commit 47ace7e

Browse files
committed
Merge pull request #92 from darfink/crates
Add Crates package manager
2 parents 65ec5ef + 3d060a7 commit 47ace7e

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

Package Managers.alfredworkflow

224 KB
Binary file not shown.

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Package Managers ([Download v3.10](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.10/Package.Managers.alfredworkflow))
1+
# Package Managers ([Download v3.11](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.11/Package.Managers.alfredworkflow))
22

33
Package Repo Search
44

@@ -10,13 +10,14 @@ Quick package/plugin/component (repo) lookup for your favourite package managers
1010
* `pkgman cachedb`: Update local database cache files
1111

1212
* `alcatraz {query}`: [Cocoa Packages](http://alcatraz.io/)
13-
* `apt-get {query}`: [Ubuntu Packages](https://apps.ubuntu.com)
1413
* `apm {query}`: [Atom Packages](https://atom.io)
14+
* `apt-get {query}`: [Ubuntu Packages](https://apps.ubuntu.com)
1515
* `bower {query}`: [Bower Components](http://bower.io) for JavaScript
1616
* `brew {query}`: [Homebrew Plugins](http://braumeister.org)
1717
* `chef {query}`: [Chef Cookbooks](https://supermarket.chef.io)
1818
* `cocoa {query}`: CocoaPods can be upgraded to CocoaDocs by changing `$apple_docs` to true in the script.
1919
* `composer {query}`: PHP [Composer Packages](https://packagist.org)
20+
* `crates {query}`: [Rust Crates](https://crates.io)
2021
* `docker {query}`: [Docker Images](http://registry.hub.docker.io)
2122
* `gems {query}`: [Ruby Gems](http://rubygems.org)
2223
* `gradle {query}`: Java [Gradle Packages](http://www.gradle.org)
@@ -56,6 +57,7 @@ The Python Package Index is very slow due to a lack on API and pagination. A min
5657
![][alcatraz]
5758
![][cocoa]
5859
![][composer]
60+
![][crates]
5961
![][pear]
6062
![][pypi]
6163
![][gems]
@@ -76,6 +78,7 @@ Featured on [Smashing Magazine](http://www.smashingmagazine.com/2013/10/25/hidde
7678
[chef]: ./screenshots/chef.png "Sample chef result"
7779
[cocoa]: ./screenshots/cocoa.png "Sample cocoa result"
7880
[composer]: ./screenshots/composer.png "Sample composer result"
81+
[crates]: ./screenshots/crates.png "Sample crates result"
7982
[docker]: ./screenshots/docker.png "Sample docker result"
8083
[gems]: ./screenshots/gems.png "Sample gems result"
8184
[grunt]: ./screenshots/grunt.png "Sample grunt result"

icon-cache/crates.png

57.4 KB
Loading

icon-src/crates.png

57.4 KB
Loading

screenshots/crates.png

257 KB
Loading

src/Crates.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace WillFarrell\AlfredPkgMan;
3+
4+
require_once('Cache.php');
5+
require_once('Repo.php');
6+
7+
class Crates extends Repo
8+
{
9+
protected $id = 'crates';
10+
protected $kind = 'libraries';
11+
protected $url = 'http://crates.io';
12+
protected $search_url = 'https://crates.io/api/v1/crates?page=1&per_page=100&q=';
13+
14+
public function search($query)
15+
{
16+
if (!$this->hasMinQueryLength($query)) {
17+
return $this->xml();
18+
}
19+
20+
$this->pkgs = $this->cache->get_query_json(
21+
'crates',
22+
$query,
23+
"{$this->search_url}{$query}"
24+
)->crates;
25+
26+
foreach($this->pkgs as $pkg) {
27+
$url = str_replace("git://", "https://", $pkg->repository);
28+
$this->cache->w->result(
29+
$pkg->id,
30+
$this->makeArg($pkg->name, $url, "\"{$pkg->name}\"=\"{$pkg->max_version}\""),
31+
$pkg->name,
32+
count($pkg->description) ? $pkg->description : $url,
33+
"icon-cache/{$this->id}.png"
34+
);
35+
36+
// Only show results up to the $max_return
37+
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
38+
break;
39+
}
40+
}
41+
42+
$this->noResults($query, "{$this->url}/search?q={$query}");
43+
44+
return $this->xml();
45+
}
46+
}
47+
48+
// Test code, uncomment to debug this script from the command-line
49+
// $repo = new Crates();
50+
// echo $repo->search('glob');

0 commit comments

Comments
 (0)