From: Scott Worley Date: Fri, 17 Jul 2020 00:10:59 +0000 (-0700) Subject: Simple command-line interface X-Git-Tag: v1.1.0~1 X-Git-Url: http://git.scottworley.com/git-cache/commitdiff_plain/347be7cf3626da2bee6487ef25b2d9dc66988a43?ds=sidebyside Simple command-line interface --- diff --git a/Changelog b/Changelog index bfacb4c..0021bf3 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,6 @@ ## [Unreleased] +### Added +- Command line interface ## [1.0.0] - 2020-07-10 Initial release diff --git a/git_cache.py b/git_cache.py index d1923cd..594fb8a 100644 --- a/git_cache.py +++ b/git_cache.py @@ -8,6 +8,7 @@ import hashlib import logging import os import subprocess +import sys from typing import Tuple @@ -77,3 +78,16 @@ def ensure_rev_available(repo: Repo, ref: Ref, rev: Rev) -> Path: subprocess.run(['git', '-C', cachedir, 'cat-file', '-e', rev], check=True) return cachedir + + +def _main() -> None: + if len(sys.argv) == 3: + print('{1} {0}'.format(*fetch(Repo(sys.argv[1]), Ref(sys.argv[2])))) + elif len(sys.argv) == 4: + print(ensure_rev_available( + Repo(sys.argv[1]), Ref(sys.argv[2]), Rev(sys.argv[3]))) + else: + usage = '''usage: git-cache repo ref [rev] +example: git-cache https://github.com/NixOS/nixpkgs.git master''' + print(usage, file=sys.stderr) + sys.exit(1) diff --git a/setup.py b/setup.py index b7bbbf1..8f5d1b2 100644 --- a/setup.py +++ b/setup.py @@ -3,5 +3,6 @@ from setuptools import setup setup( name="git_cache", version="0.0.1-pre", + entry_points={'console_scripts': ['git-cache = git_cache:_main']}, py_modules=['git_cache'], )