├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── cli.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '6' 4 | - '4' 5 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const chalk = require('chalk'); 4 | const figures = require('figures'); 5 | const inquirer = require('inquirer'); 6 | const meow = require('meow'); 7 | const opn = require('opn'); 8 | const githubSearchRepos = require('github-search-repos'); 9 | 10 | const cli = meow(` 11 | Usage 12 | $ github-search-repos 13 | $ github-search-repos gulp 14 | $ github-search-repos gulp+languge:javascript 15 | 16 | Options 17 | -i, --interactive Show results in interactive interface 18 | -s, --sort Sort results by either \`stars\`, \`forks\` or \`updated\` 19 | -t, --token GitHub authentication token 20 | `, { 21 | boolean: ['interactive'], 22 | string: [ 23 | 'sort', 24 | 'token' 25 | ], 26 | alias: { 27 | i: 'interactive', 28 | s: 'sort', 29 | t: 'token' 30 | } 31 | }); 32 | 33 | const listResults = repos => { 34 | inquirer.prompt([{ 35 | name: 'results', 36 | message: 'Search results:', 37 | type: 'list', 38 | choices: repos.map(x => { 39 | const stars = x.stargazers_count + figures.star; 40 | const fullName = x.full_name.split('/'); 41 | 42 | return { 43 | name: fullName[0] + '/' + chalk.blue.bold(fullName[1]) + ' ' + chalk.dim(stars), 44 | value: x.html_url 45 | }; 46 | }) 47 | }], answer => { 48 | opn(answer.results); 49 | }); 50 | }; 51 | 52 | const init = () => { 53 | inquirer.prompt([{ 54 | name: 'query', 55 | message: 'Search for GitHub repositories' 56 | }], answer => { 57 | githubSearchRepos(answer.query).then(data => { 58 | listResults(data.items); 59 | }); 60 | }); 61 | }; 62 | 63 | if (cli.input.length === 0) { 64 | init(); 65 | } else if (cli.flags.interactive) { 66 | githubSearchRepos(cli.input[0], cli.flags).then(data => { 67 | listResults(data.items); 68 | }); 69 | } else { 70 | githubSearchRepos(cli.input[0], cli.flags).then(data => { 71 | for (const x of data.items) { 72 | const stars = x.stargazers_count + figures.star; 73 | const fullName = x.full_name.split('/'); 74 | 75 | console.log([ 76 | `${fullName[0]}/${chalk.blue.bold(fullName[1])} ${chalk.dim(stars)}`, 77 | x.description, 78 | chalk.dim(x.html_url), 79 | '' 80 | ].join('\n')); 81 | } 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Martensson (github.com/kevva) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-search-repos-cli", 3 | "version": "1.0.0", 4 | "description": "Search GitHub repositories", 5 | "license": "MIT", 6 | "repository": "kevva/github-search-repos-cli", 7 | "author": { 8 | "name": "Kevin Martensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "bin": { 13 | "github-search-repos": "cli.js" 14 | }, 15 | "engines": { 16 | "node": ">=4" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava" 20 | }, 21 | "files": [ 22 | "cli.js" 23 | ], 24 | "keywords": [ 25 | "cli-app", 26 | "cli", 27 | "github", 28 | "repos", 29 | "search", 30 | "token" 31 | ], 32 | "dependencies": { 33 | "chalk": "^1.0.0", 34 | "figures": "^1.3.5", 35 | "github-search-repos": "^3.0.0", 36 | "inquirer": "^0.11.1", 37 | "meow": "^3.7.0", 38 | "opn": "^4.0.2" 39 | }, 40 | "devDependencies": { 41 | "ava": "*", 42 | "execa": "^0.4.0", 43 | "xo": "*" 44 | }, 45 | "xo": { 46 | "esnext": true 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # github-search-repos-cli [![Build Status](https://travis-ci.org/kevva/github-search-repos-cli.svg?branch=master)](https://travis-ci.org/kevva/github-search-repos-cli) 2 | 3 | > Search GitHub repositories 4 | 5 | ![](https://cloud.githubusercontent.com/assets/709159/7231098/61955acc-e773-11e4-9f4b-e96657672cdd.png) 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install --global github-search-repos-cli 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ``` 18 | $ github-search-repos --help 19 | 20 | Usage 21 | $ github-search-repos 22 | $ github-search-repos gulp 23 | $ github-search-repos gulp+languge:javascript 24 | 25 | Options 26 | -i, --interactive Show results in interactive interface 27 | -s, --sort Sort results by either `stars`, `forks` or `updated` 28 | -t, --token GitHub authentication token 29 | ``` 30 | 31 | 32 | ## Related 33 | 34 | * [github-search-repos](https://github.com/kevva/github-search-repos) - API for this module 35 | 36 | 37 | ## License 38 | 39 | MIT © [Kevin Martensson](https://github.com/kevva) 40 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import execa from 'execa'; 3 | 4 | test('show help screen', async t => { 5 | t.regex(await execa.stdout('./cli.js', ['--help']), /Search GitHub repositories/); 6 | }); 7 | 8 | test('show version', async t => { 9 | t.is(await execa.stdout('./cli.js', ['--version']), require('./package').version); 10 | }); 11 | --------------------------------------------------------------------------------