Add overwrite argument
This commit is contained in:
parent
5fe8f8dfd1
commit
f425fc9ccc
12
link-tool.py
12
link-tool.py
|
@ -65,8 +65,13 @@ def load_config(conf_path: str) -> Tuple[Conf, List[Link]]:
|
|||
|
||||
return conf, links
|
||||
|
||||
def make_link(links: List[Link], dry_run=False):
|
||||
def make_link(links: List[Link], dry_run=False, overwrite=False):
|
||||
for link in links:
|
||||
if os.path.exists(link.dst):
|
||||
if not overwrite:
|
||||
logger.info('dst exists, skipping: {}'.format(link.dst))
|
||||
return
|
||||
|
||||
if os.path.exists(link.dst):
|
||||
logger.warning('dst exists, removing: {}'.format(link.dst))
|
||||
if not dry_run:
|
||||
|
@ -86,6 +91,8 @@ def main():
|
|||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--config', required=True,
|
||||
help='configuration file')
|
||||
parser.add_argument('-o', '--overwrite', action='store_true',
|
||||
help='overwrite dst when exists')
|
||||
parser.add_argument('-n', '--dry-run', action='store_true',
|
||||
help='dry run without actually create link')
|
||||
parser.add_argument('-v', '--verbose', action='store_true',
|
||||
|
@ -96,6 +103,7 @@ def main():
|
|||
config_path = args.config
|
||||
verbose = args.verbose
|
||||
dry_run = args.dry_run
|
||||
overwrite = args.overwrite
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO)
|
||||
|
||||
|
@ -115,7 +123,7 @@ def main():
|
|||
logger.info('the CWD realpath: {}'.format(os.path.realpath(chdir_target)))
|
||||
os.chdir(chdir_target)
|
||||
|
||||
make_link(links, dry_run=dry_run)
|
||||
make_link(links, dry_run=dry_run, overwrite=overwrite)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue