Commit eced90e0 authored by KDercksen's avatar KDercksen
Browse files

Initial commit

parents
"THE BEER-WARE LICENSE" (Revision 42):
<mail@koendercksen.com> wrote this project. As long as you retain this notice
you can do whatever you want with this stuff. If we meet some day, and you
think this stuff is worth it, you can buy me a beer in return. - Koen Dercksen
cloogle-cli
=========
```cloogle-cli``` is a commandline frontend for the
[Cloogle](http://github.com/dopefishh/cloogle) API. At the moment, it supports
the full API functionality.
##Usage
cloogle-cli [OPTIONS] <searchstring>
### Available options
- **--url <URL>**: supply a custom API URL (default: "cloogle.org/api.php")
- **--filtermod <MODULE>**: filters results on given module (WARNING: this is case sensitive)
```cloogle-cli``` supports different output formats:
- **--table**: tabulated output of search results
- **--minimal**: minimal listing of results
- maybe more to come
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tabulate import tabulate
import argparse
import errno
import json
import re
import requests
import sys
def get_data(**kwargs):
url = kwargs['url']
payload = {'str': kwargs['searchstr']}
if kwargs['filtermod'] != "":
payload.update({'mod': kwargs['filtermod']})
response = requests.get(url, params=payload)
return response.json()
def clean_tabs(data, field):
for d in data:
d[field] = re.sub(r'\t+', ' ', d[field])
def minimal_output(data):
for d in data:
print('{}'.format(d['func'].split('//')[0]))
def table_output(data):
o = []
for d in data:
fc = d['func'].split('//')
if len(fc) > 1:
o.append((d['module'], fc[0], fc[1]))
else:
o.append((d['module'], fc[0], ""))
print(tabulate(o, headers=['Module', 'Function', '(Comment)']))
if __name__ == "__main__":
p = argparse.ArgumentParser('cloogle-cli')
p.add_argument('searchstr', type=str, help='pattern to search for')
p.add_argument('-u', '--url', type=str, default="http://cloogle.org/api.php")
p.add_argument('-f', '--filtermod', metavar='MODULE', type=str, default="")
g = p.add_argument_group('Output formatting').add_mutually_exclusive_group()
g.add_argument('--table', action='store_true')
g.add_argument('--minimal', action='store_true')
g.add_argument('--verbose', action='store_true')
args = p.parse_args()
print(args)
data = get_data(**vars(args))
clean_tabs(data['data'], 'func')
if data['msg'] != "Success":
print('Unsuccesful response ({}).'.format(data['msg']), file=sys.stderr)
sys.exit(errno.ENOENT)
if args.table: table_output(data['data'])
else: minimal_output(data['data'])
sys.exit()
#!/usr/bin/env python
from pip.req import parse_requirements
from setuptools import setup
install_reqs = parse_requirements('requirements.txt', session=False)
setup(
name='cloogle-cli',
version='0.1',
description='Cloogle CLI frontend',
author='Koen Dercksen',
author_email='mail@koendercksen.com',
url='http://github.com/KDercksen/cloogle-cli',
install_requires=[str(ir.req) for ir in install_reqs],
scripts=['cloogle-cli.py'],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment