more entries in the catalog ; more readme and faq ; onging impl

This commit is contained in:
setop 2023-02-09 12:39:36 +01:00
parent 0e9eb6a6a9
commit d6a31f58f9
4 changed files with 77 additions and 25 deletions

View File

@ -1,6 +1,6 @@
ab: ab:
name: Apache Benchmark name: Apache Benchmark
desc: desc: a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server
arc: arc:
desc: Easily create & extract archives, and compress & decompress files of various formats desc: Easily create & extract archives, and compress & decompress files of various formats
@ -69,7 +69,7 @@ gron:
github: tomnomnom/gron github: tomnomnom/gron
grype: grype:
decs: A vulnerability scanner for container images and filesystems desc: A vulnerability scanner for container images and filesystems
github: anchore/grype github: anchore/grype
hey: hey:
@ -200,9 +200,9 @@ terminews:
desc: RSS client in the terminal desc: RSS client in the terminal
github: antavelos/terminews github: antavelos/terminews
tldr: #tldr:
desc: Collaborative cheatsheets for console commands ; must choose a client # desc: Collaborative cheatsheets for console commands ; must choose a client
website: https://tldr.sh/ # website: https://tldr.sh/
tmux: tmux:
desc: terminal multiplexer desc: terminal multiplexer

View File

@ -1,12 +1,12 @@
"""Cliget - install cli tools in you user profile """Cliget - install cli tools in you user profile
Usage: Usage:
cliget [-c URL] list cliget [-v] [-c URL] list
cliget [-c URL] search PAT cliget [-v] [-c URL] search PAT
cliget [-c URL] update [--all] [TOOL ...] cliget [-v] [-c URL] update [--all] [TOOL ...]
list list all installed tools list list all installed tools
search search for tools in the catalog with the given pattenr search search for tools in the catalog with the given pattern
update list all updatable tools update list all updatable tools
update TOOL update tools update TOOL update tools
update --all update all updatable tools update --all update all updatable tools
@ -15,36 +15,52 @@ update --all update all updatable tools
Options: Options:
-h, --help -h, --help
-c, --catalog URL -c, --catalog URL
-v, --verbose
""" """
from yaml import load, SafeLoader import sys, os
import semver
from docopt import docopt from docopt import docopt
from yaml import load, SafeLoader
from semver import VersionInfo
import re
from subprocess import run, CalledProcessError, TimeoutExpired from subprocess import run, CalledProcessError, TimeoutExpired
from fuzzywuzzy import fuzz
def debug(*mess):
#print("DEBUG", mess)
pass
class DotDict(dict): class DotDict(dict):
def __getattr__(self, name): def __getattr__(self, name):
return self[name] if name in self else None return self[name] if name in self else None
def loadcatalog(options)->dict: def loadcatalog(options)->dict:
catalog=options.get('--catalog', 'catalog.yaml') catalog=options.get('__catalog', 'catalog.yaml')
return load(open(catalog),SafeLoader) return load(open(catalog), SafeLoader)
def find_semver(s:str) -> VersionInfo:
ver = VersionInfo(0,0,0)
try:
ver = VersionInfo.parse(s)
except ValueError:
try:
ver = VersionInfo(*list(i.group(0) for i in re.finditer('\d+', s))[:3])
except Exception as e:
debug("parse error", e)
return ver
ver = semver.VersionInfo.parse('1.2.3-pre.2+build.4')
#print(ver.major, ver.minor, ver.patch)
_version = lambda cmd: run([cmd, '--version'], input='', text=True, capture_output=True, check=True, timeout=0.1).stdout.split('\n')[0] _version = lambda cmd: run([cmd, '--version'], input='', text=True, capture_output=True, check=True, timeout=0.1).stdout.split('\n')[0]
def debug(mess): def _internal_list(options) -> tuple[str,VersionInfo]:
#print(mess) """list installed tools and their version"""
pass
def dolist(options):
ctl = loadcatalog(options) ctl = loadcatalog(options)
for cli,_ in ctl.items(): for cli, props in ctl.items():
# search in path # search in path
try: try:
debug(cli, _version(cli)) vers = _version(cli)
debug(cli, vers)
yield cli, props, find_semver(vers)
except CalledProcessError: except CalledProcessError:
debug(cli, "call error") debug(cli, "call error")
except TimeoutExpired: except TimeoutExpired:
@ -52,12 +68,42 @@ def dolist(options):
except FileNotFoundError: except FileNotFoundError:
debug(cli, "not found") debug(cli, "not found")
def dolist(options):
for (cli, _, ver) in _internal_list(options):
print(cli, ver)
def dosearch(options):
pat = options.PAT
ctl = loadcatalog(options)
L = []
for cli, props in ctl.items():
debug(cli, props)
rtitle = fuzz.ratio(cli, pat)
rdesc = fuzz.partial_ratio(props['desc'], pat)
score = 2 * rtitle + rdesc
L.append((cli, props['desc'], score))
L = sorted(L, key=lambda x: -x[-1])
# TODO format a as table
print("\n".join("|".join(map(str,l)) for l in L[:10]))
def dolistupdate(options):
print("look for updatables")
for (cli, props, ver) in _internal_list(options):
# get last version online
if props.github:
pass
pass
if __name__ == '__main__': if __name__ == '__main__':
options = docopt(__doc__, version='Cliget 0.1.0') options = docopt(__doc__, version='Cliget 0.1.0')
print(options) options = DotDict({k.replace('-','_'):v for (k,v) in options.items() if v is not None})
options = DotDict(options) debug(options)
if options.list: if options.list:
dolist(options) dolist(options)
elif options.search: elif options.search:
dosearch(options) dosearch(options)
elif options.update:
if not options.__all and len(options.TOOL)==0:
dolistupdate(options)
else:
print("not implemented")

4
cmd.txt Normal file
View File

@ -0,0 +1,4 @@
. ./venv/bin/activate

View File

@ -1,3 +1,5 @@
pyyaml pyyaml
docopt docopt
semver semver
fuzzywuzzy
python-Levenshtein