From dc9f814ae99acb3582afe1e6f502b23d0726f236 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Mon, 25 Oct 2021 07:41:03 +0200 Subject: [PATCH] Add a -C like make and git to tell where to work. --- powrap/__init__.py | 2 +- powrap/powrap.py | 23 ++++++++++++++++++++--- setup.cfg | 4 ---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/powrap/__init__.py b/powrap/__init__.py index 5c30b07..5f75a9e 100644 --- a/powrap/__init__.py +++ b/powrap/__init__.py @@ -2,4 +2,4 @@ __author__ = """Julien Palard""" __email__ = "julien@palard.fr" -__version__ = "0.4.0" +__version__ = "1.0.0" diff --git a/powrap/powrap.py b/powrap/powrap.py index 3348bdf..d171cce 100644 --- a/powrap/powrap.py +++ b/powrap/powrap.py @@ -2,6 +2,7 @@ import argparse import sys +import os from typing import Iterable import difflib from pathlib import Path @@ -96,7 +97,18 @@ def parse_args(): 127:error running msgcat""", ) parser.add_argument( - "--modified", "-m", action="store_true", help="Use git to find modified files." + "--modified", + "-m", + action="store_true", + help="Use git to find modified files instead of passing them as arguments.", + ) + parser.add_argument( + "-C", + help="To use with --modified to tell where the git " + "repo is, in case it's not in the current working directory.", + type=Path, + dest="git_root", + default=Path.cwd(), ) parser.add_argument( "--quiet", "-q", action="store_true", help="Do not show progress bar." @@ -115,7 +127,6 @@ def parse_args(): "Return code 0 means nothing would change. " "Return code 1 means some files would be reformatted.", ) - parser.add_argument( "--version", action="version", version="%(prog)s " + __version__ ) @@ -129,15 +140,21 @@ def parse_args(): if not args.po_files and not args.modified: parser.print_help() sys.exit(1) + if args.po_files and args.modified: + parser.print_help() + sys.exit(1) return args def main(): """Powrap main entrypoint (parsing command line and all).""" args = parse_args() + if args.git_root: + os.chdir(args.git_root) if args.modified: git_status = check_output( - ["git", "status", "--porcelain", "--no-renames"], encoding="utf-8" + ["git", "status", "--porcelain", "--no-renames"], + encoding="utf-8", ) git_status_lines = [ line.split(maxsplit=2) for line in git_status.split("\n") if line diff --git a/setup.cfg b/setup.cfg index e73fac4..6302308 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,10 +14,6 @@ classifiers = License :: OSI Approved :: MIT License Natural Language :: English Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 [options] packages = powrap