2020-08-18 10:15:26 -07:00
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
class PathResolverAction(argparse.Action):
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
path = Path(values).resolve()
|
2020-09-02 21:26:00 -07:00
|
|
|
if not path.exists():
|
|
|
|
raise ValueError(f"{path} doesn't exist.")
|
2020-08-18 10:15:26 -07:00
|
|
|
|
|
|
|
if self.dest == "icons_folder_path":
|
|
|
|
if not path.is_dir():
|
|
|
|
raise ValueError("icons_folder_path must be a directory")
|
2020-09-02 21:26:00 -07:00
|
|
|
|
|
|
|
elif self.dest == "download_path":
|
|
|
|
if not path.is_dir():
|
|
|
|
raise ValueError("download_path must be a directory")
|
2020-08-18 10:15:26 -07:00
|
|
|
|
|
|
|
setattr(namespace, self.dest, str(path))
|