Sybren A. Stüvel 5c8e074c68 Implemented simple 'bat pack' CLI command
No path rewriting yet, just simply copying the dependencies. They are
copied to the target directory + the path relative to the current working
directory. For example:

bat pack scenes/05-barber/05_02_C-agent_focused/05_02_C.lighting.blend /tmp/packer

will write to
/tmp/packer/scenes/05-barber/05_02_C-agent_focused/05_02_C.lighting.blend
and will copy ./path/to/file → /tmp/packer/path/to/file
2018-03-02 17:59:04 +01:00

24 lines
686 B
Python

"""Common functionality for CLI parsers."""
import pathlib
def add_flag(argparser, flag_name: str, **kwargs):
"""Add a CLI argument for the flag.
The flag defaults to False, and when present on the CLI stores True.
"""
argparser.add_argument('-%s' % flag_name[0],
'--%s' % flag_name,
default=False,
action='store_true',
**kwargs)
def shorten(cwd: pathlib.Path, somepath: pathlib.Path) -> pathlib.Path:
"""Return 'somepath' relative to CWD if possible."""
try:
return somepath.relative_to(cwd)
except ValueError:
return somepath