]> git.scottworley.com Git - git-cache/commitdiff
Simple command-line interface
authorScott Worley <scottworley@scottworley.com>
Fri, 17 Jul 2020 00:10:59 +0000 (17:10 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 17 Jul 2020 00:14:43 +0000 (17:14 -0700)
Changelog
git_cache.py
setup.py

index bfacb4cd7b91bc66595011bf45bc2464c91f9aef..0021bf3d1bccacc809a12e42e6ac584558f13081 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,6 @@
 ## [Unreleased]
 ## [Unreleased]
+### Added
+- Command line interface
 
 ## [1.0.0] - 2020-07-10
 Initial release
 
 ## [1.0.0] - 2020-07-10
 Initial release
index d1923cd5a7ee287cfbc0da2625e91b1dfa670216..594fb8a77cdad825a2783723ffc04bbd6c951b71 100644 (file)
@@ -8,6 +8,7 @@ import hashlib
 import logging
 import os
 import subprocess
 import logging
 import os
 import subprocess
+import sys
 
 from typing import Tuple
 
 
 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
     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)
index b7bbbf1ab603809986d998ab84213a5736c0687b..8f5d1b29d004c7ee56dcd31d38ec8c3e004d6bd8 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,5 +3,6 @@ from setuptools import setup
 setup(
     name="git_cache",
     version="0.0.1-pre",
 setup(
     name="git_cache",
     version="0.0.1-pre",
+    entry_points={'console_scripts': ['git-cache = git_cache:_main']},
     py_modules=['git_cache'],
 )
     py_modules=['git_cache'],
 )