Commit eced90e0 authored by KDercksen's avatar KDercksen
Browse files

Initial commit

"THE BEER-WARE LICENSE" (Revision 42):
<> 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``` is a commandline frontend for the
[Cloogle]( API. At the moment, it supports
the full API functionality.
cloogle-cli [OPTIONS] <searchstring>
### Available options
- **--url <URL>**: supply a custom API URL (default: "")
- **--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:
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]))
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="")
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()
data = get_data(**vars(args))
clean_tabs(data['data'], 'func')
if data['msg'] != "Success":
print('Unsuccesful response ({}).'.format(data['msg']), file=sys.stderr)
if args.table: table_output(data['data'])
else: minimal_output(data['data'])
#!/usr/bin/env python
from pip.req import parse_requirements
from setuptools import setup
install_reqs = parse_requirements('requirements.txt', session=False)
description='Cloogle CLI frontend',
author='Koen Dercksen',
install_requires=[str(ir.req) for ir in install_reqs],
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