Skip to content

Commit

Permalink
improved help layout and __main__ formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfpackWilson committed Aug 28, 2020
1 parent 184cab1 commit b8479ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ catminer run -h
```
which yields the following:
```
usage: catminer run [-h] [-b [path]] [-i path] [-o path] [-f] [-t {xml,json}]
usage: catminer run [-h] [-i path] [-o path] [-f] [-t {xml,json}] [-b [path]]
[-r]
Run catminer using these commands:
optional arguments:
-h, --help show this help message and exit
-b [path], --bat-file [path]
generate a .bat file for easier automation
-i path, --in-dir path
set the run directory
-o path, --out-dir path
set the output directory
-f, --force-export export previously exported files
-t {xml,json}, --file-type {xml,json}
choose the output file type (default: xml)
-r, --relative-path use the relative path to run catminer
.bat file:
extra commands to make a .bat file instead
-b [path], --bat-file [path]
generate a .bat file for easier automation
-r, --relative-path use the relative path to create the .bat file
```

The supported outputs are dependent on [pyvba](https://pypi.org/project/pyvba/).
Expand Down
24 changes: 15 additions & 9 deletions catminer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ def main():
# 'run' command
run_parser = subparsers.add_parser('run', description='Run catminer using these commands:',
help='run the batch process')
bat_group = run_parser.add_argument_group('.bat file', 'extra commands to make a .bat file instead')

run_parser.add_argument('-b', '--bat-file', nargs='?', const=os.getcwd(), default=os.getcwd(), type=str,
metavar='path', help='generate a .bat file for easier automation')
run_parser.add_argument('-i', '--in-dir', nargs=1, default=os.getcwd(), type=str, metavar='path',
help='set the run directory')
run_parser.add_argument('-o', '--out-dir', nargs=1, type=str, metavar='path', help='set the output directory')
run_parser.add_argument('-f', '--force-export', action='store_true', help='export previously exported files')
run_parser.add_argument('-t', '--file-type', nargs=1, default='xml', type=str, choices=['xml', 'json'],
help='choose the output file type (default: xml)')
run_parser.add_argument('-r', '--relative-path', action='store_true', help='use the relative path to run catminer')

# parse args
args = None
# generate a bat file
bat_group.add_argument('-b', '--bat-file', nargs='?', const=os.getcwd(), default=os.getcwd(), type=str,
metavar='path', help='generate a .bat file for easier automation')
bat_group.add_argument('-r', '--relative-path', action='store_true',
help='use the relative path to create the .bat file')

# parse args
if 'pytest' in sys.argv[0]:
args = parser.parse_args([])
else:
Expand Down Expand Up @@ -90,17 +92,21 @@ def main():

# create bat file or start miner
if '-b' in sys.argv:
bat_str = f'python catminer run {"-f " if d_args.get("force_export", False) else ""}-t {args.file_type}^\n' + \
f' -i "{"." if "-r" in sys.argv else args.in_dir}"^\n' + \
bat_str = f'python catminer run ' \
f'{"-f " if d_args.get("force_export", False) else ""}' \
f'-t {args.file_type}^\n' \
f' -i "{"." if "-r" in sys.argv else args.in_dir}"^\n' \
f' -o "{os.path.join(".", "catminer") if "-r" in sys.argv else args.out_dir}"\n'

with open(os.path.join(args.bat_file, "catminer.bat"), 'w') as f:
f.write(bat_str)
f.close()
else:
file_type = {'xml': catminer.XML, 'json': catminer.JSON}
miner = catminer.CATMiner(args.in_dir, args.out_dir, file_type[args.file_type],
force_export=d_args.get("force_export", False))
miner = catminer.CATMiner(
args.in_dir, args.out_dir, file_type[args.file_type],
force_export=d_args.get("force_export", False),
)
miner.begin()


Expand Down

0 comments on commit b8479ff

Please sign in to comment.