Small refactoring in argument parsing.

This commit is contained in:
antoine 2020-01-13 23:12:15 +01:00
parent 46ea23e16c
commit a4ad750a16
2 changed files with 32 additions and 44 deletions

View File

@ -1,5 +1,5 @@
# Potodo
Potodo, a (almost) flawless TODO/progress listing CLI tool for po files
Potodo, a (almost) flawless TODO/progress listing CLI tool for po files.
## Installation
@ -10,22 +10,23 @@ pip install potodo
## Usage
```
usage: potodo [-h] [-p PATH] [-l] [-f] [-o] [-n] [-a ABOVE] [-b BELOW]
usage: potodo [-h] [-p PATH] [-a X] [-b X] [-f] [-o] [-n] [-c] [-j]
[--version]
List and prettify the po files left to translate
Sequence and prettify the po files left to translate.
optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH Execute Potodo in the given path
-l, --matching-files Suppress normal output; instead print the name of each matching po file from which output would normally have been printed.
-f, --fuzzy Will only print files marked as fuzzys
-o, --offline Will not do any fetch to GitHub/online if given
-n, --no-reserved Will not print the info about reserved files
-j, --json Will produce JSON-formatted output
-a ABOVE, --above ABOVE
Will list all TODOs ABOVE given INT% completion
-b BELOW, --below BELOW
Will list all TODOs BELOW given INT% completion
-p PATH, --path PATH execute Potodo in PATH
-a X, --above X list all TODOs above given X% completion
-b X, --below X list all TODOs below given X% completion
-f, --fuzzy print only files marked as fuzzys
-o, --offline don't perform any fetching to GitHub/online
-n, --no-reserved don't print info about reserved files
-c, --counts render list with the count of remaining entries
(translate or review) rather than percentage done
-j, --json format output as JSON.
--version show program's version number and exit
```
## Contributing
@ -43,4 +44,4 @@ cat <<EOF > .git/hooks/pre-commit
exec tox -s -p all
EOF
```
may help.
may help.

View File

@ -6,7 +6,6 @@ import json
import statistics
from typing import Any, Dict, List, Mapping, Sequence, Tuple
from pathlib import Path
from potodo import __version__
from potodo._github import get_reservation_list
@ -238,58 +237,56 @@ def buffer_add(
def main() -> None:
parser = argparse.ArgumentParser(
prog="potodo",
description="Sequence and prettify the po files left to translate",
description="Sequence and prettify the po files left to translate.",
)
parser.add_argument(
"-p", "--path", type=Path, help="Execute Potodo in the given path"
)
parser.add_argument("-p", "--path", help="execute Potodo in PATH")
parser.add_argument(
"-a",
"--above",
metavar="X",
type=int,
help="Will list all TODOs ABOVE given INT%% completion",
help="list all TODOs above given X%% completion",
)
parser.add_argument(
"-b",
"--below",
metavar="X",
type=int,
help="Will list all TODOs BELOW given INT%% completion",
help="list all TODOs below given X%% completion",
)
parser.add_argument(
"-f",
"--fuzzy",
action="store_true",
help="Will only print files marked as fuzzys",
"-f", "--fuzzy", action="store_true", help="print only files marked as fuzzys",
)
parser.add_argument(
"-o",
"--offline",
action="store_true",
help="Will not do any fetch to GitHub/online if given",
help="don't perform any fetching to GitHub/online",
)
parser.add_argument(
"-n",
"--no-reserved",
dest="hide_reserved",
action="store_true",
help="Will not print the info about reserved files",
help="don't print info about reserved files",
)
parser.add_argument(
"-c",
"--counts",
action="store_true",
help="Render list with the count of remaining entries "
help="render list with the count of remaining entries "
"(translate or review) rather than percentage done",
)
parser.add_argument(
"-j", "--json", action="store_true", help="Format output as JSON.",
"-j", "--json", action="store_true", help="format output as JSON.",
)
parser.add_argument(
@ -297,19 +294,9 @@ def main() -> None:
)
args = parser.parse_args()
# If no path is specified, then use the current path
if args.path:
path = str(args.path)
else:
path = os.getcwd()
exec_potodo(
path,
args.above,
args.below,
args.fuzzy,
args.offline,
args.no_reserved,
args.counts,
args.json,
)
# If no path is specified, use current directory
if not args.path:
args.path = os.getcwd()
exec_potodo(**vars(args))