#default_exp cli #export from fastcore.utils import * import ghapi.core as gh,inspect from ghapi.core import * from collections import defaultdict #export def _parse_args(a): "Extract positional and keyword arguments from `a`=`sys.argv`" pos,kw = [],{} i=1 while i") call = f(pos, api) return call if kw.get('help', None) else call(*pos, **kw) #export def _ghapi(arg, api): for part in arg.pop(0).split('.'): api = getattr(api,part) return api #hide #export def ghapi(): "Python backend for the `ghapi` command, which calls an endpoint by operation name" res = _call_api(_ghapi) if isinstance(res, (gh._GhObj,dict)): print(res) elif res: print(inspect.signature(res)) ! ghapi git.get_ref fastai ghapi-test --ref heads/master ! ghapi git.get_ref --help ! ghapi create_release --help #export def _ghpath(arg, api): return api[arg.pop(0),arg.pop(0)] #hide #export def ghpath(): "Python backend for the `ghpath` command, which calls an endpoint by path" print(_call_api(_ghpath) or '') ! ghpath '/repos/{owner}/{repo}/git/ref/{ref}' get fastai ghapi-test --ref heads/master #hide #export def ghraw(): "Python backend for the `ghraw` command, which calls a fully-specified endpoint" cmd,api,pos,kw = _api() if not pos: return print(f"Usage: `{cmd}` operation ") print(api(*pos, **kw)) ! ghraw /repos/fastai/ghapi-test/git/ref/heads/master get #hide #export _TAB_COMPLETION=""" _do_ghapi_completions() { COMP="$(completion-ghapi "${COMP_WORDS[1]}")" COMPREPLY=($COMP) } complete -F _do_ghapi_completions ghapi """ #hide #export def completion_ghapi(): "Python backend for `completion-ghapi` command" if len(sys.argv) == 2 and sys.argv[1] == '--install': print(_TAB_COMPLETION) return *parts,final = (sys.argv[1] if len(sys.argv)>1 else '').split('.') call = GhApi() for part in parts: call = getattr(call,part) if hasattr(call,final): res = [final] else: res = [o for o in dir(call) if o.startswith(final) and not o.startswith('_')] pre = '.'.join(parts+[final]) print(' '.join(pre + remove_prefix(o, final) for o in res)) ! completion-ghapi git ! completion-ghapi gi ! completion-ghapi git. ! completion-ghapi git.g #hide ! completion-ghapi --install #hide from nbdev.export import notebook2script notebook2script()