From 347be7cf3626da2bee6487ef25b2d9dc66988a43 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 16 Jul 2020 17:10:59 -0700 Subject: [PATCH] Simple command-line interface --- Changelog | 2 ++ git_cache.py | 14 ++++++++++++++ setup.py | 1 + 3 files changed, 17 insertions(+) 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'], ) -- 2.44.1