more entries in the catalog ; more readme and faq ; onging impl
This commit is contained in:
63
cliget.py
Normal file
63
cliget.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""Cliget - install cli tools in you user profile
|
||||
|
||||
Usage:
|
||||
cliget [-c URL] list
|
||||
cliget [-c URL] search PAT
|
||||
cliget [-c URL] update [--all] [TOOL ...]
|
||||
|
||||
list list all installed tools
|
||||
search search for tools in the catalog with the given pattenr
|
||||
update list all updatable tools
|
||||
update TOOL update tools
|
||||
update --all update all updatable tools
|
||||
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
-c, --catalog URL
|
||||
"""
|
||||
|
||||
from yaml import load, SafeLoader
|
||||
import semver
|
||||
from docopt import docopt
|
||||
from subprocess import run, CalledProcessError, TimeoutExpired
|
||||
|
||||
class DotDict(dict):
|
||||
def __getattr__(self, name):
|
||||
return self[name] if name in self else None
|
||||
|
||||
def loadcatalog(options)->dict:
|
||||
catalog=options.get('--catalog', 'catalog.yaml')
|
||||
return load(open(catalog),SafeLoader)
|
||||
|
||||
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]
|
||||
|
||||
def debug(mess):
|
||||
#print(mess)
|
||||
pass
|
||||
|
||||
def dolist(options):
|
||||
ctl = loadcatalog(options)
|
||||
for cli,_ in ctl.items():
|
||||
# search in path
|
||||
try:
|
||||
debug(cli, _version(cli))
|
||||
except CalledProcessError:
|
||||
debug(cli, "call error")
|
||||
except TimeoutExpired:
|
||||
debug(cli, "timeout")
|
||||
except FileNotFoundError:
|
||||
debug(cli, "not found")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = docopt(__doc__, version='Cliget 0.1.0')
|
||||
print(options)
|
||||
options = DotDict(options)
|
||||
if options.list:
|
||||
dolist(options)
|
||||
elif options.search:
|
||||
dosearch(options)
|
Reference in New Issue
Block a user