mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 03:24:17 +00:00
implement import -l --link for #110
This commit is contained in:
@@ -610,11 +610,6 @@ class Cfg:
|
|||||||
|
|
||||||
if self.key_imp_link not in self.lnk_settings:
|
if self.key_imp_link not in self.lnk_settings:
|
||||||
self.lnk_settings[self.key_imp_link] = self.default_link_imp
|
self.lnk_settings[self.key_imp_link] = self.default_link_imp
|
||||||
elif self.lnk_settings[self.key_imp_link] == self.lnk_children:
|
|
||||||
msg = '\"{}\" not supported in {}'.format(self.lnk_children,
|
|
||||||
self.key_imp_link)
|
|
||||||
self.log.err(msg)
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
key = self.lnk_settings[self.key_imp_link]
|
key = self.lnk_settings[self.key_imp_link]
|
||||||
if key != self.lnk_parent and \
|
if key != self.lnk_parent and \
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ stores all options to use across dotdrop
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import socket
|
import socket
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
@@ -31,6 +32,11 @@ NAME = 'dotdrop'
|
|||||||
CONFIG = 'config.yaml'
|
CONFIG = 'config.yaml'
|
||||||
HOMECFG = '~/.config/{}'.format(NAME)
|
HOMECFG = '~/.config/{}'.format(NAME)
|
||||||
|
|
||||||
|
OPT_LINK = {
|
||||||
|
'nolink': LinkTypes.NOLINK,
|
||||||
|
'link': LinkTypes.PARENT,
|
||||||
|
'link_children': LinkTypes.CHILDREN}
|
||||||
|
|
||||||
BANNER = """ _ _ _
|
BANNER = """ _ _ _
|
||||||
__| | ___ | |_ __| |_ __ ___ _ __
|
__| | ___ | |_ __| |_ __ ___ _ __
|
||||||
/ _` |/ _ \| __/ _` | '__/ _ \| '_ |
|
/ _` |/ _ \| __/ _` | '__/ _ \| '_ |
|
||||||
@@ -42,7 +48,7 @@ USAGE = """
|
|||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dotdrop install [-VbtfndD] [-c <path>] [-p <profile>] [<key>...]
|
dotdrop install [-VbtfndD] [-c <path>] [-p <profile>] [<key>...]
|
||||||
dotdrop import [-Vbld] [-c <path>] [-p <profile>] <path>...
|
dotdrop import [-Vbd] [-c <path>] [-p <profile>] [-l <link>] <path>...
|
||||||
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
|
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
|
||||||
[-o <opts>] [-C <file>...] [-i <pattern>...]
|
[-o <opts>] [-C <file>...] [-i <pattern>...]
|
||||||
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
||||||
@@ -59,11 +65,11 @@ Options:
|
|||||||
-C --file=<path> Path of dotfile to compare.
|
-C --file=<path> Path of dotfile to compare.
|
||||||
-i --ignore=<pattern> Pattern to ignore.
|
-i --ignore=<pattern> Pattern to ignore.
|
||||||
-o --dopts=<opts> Diff options [default: ].
|
-o --dopts=<opts> Diff options [default: ].
|
||||||
|
-l --link=<link> "link_import_default" (nolink|link|link_children).
|
||||||
-n --nodiff Do not diff when installing.
|
-n --nodiff Do not diff when installing.
|
||||||
-t --temp Install to a temporary directory for review.
|
-t --temp Install to a temporary directory for review.
|
||||||
-T --template Only template dotfiles.
|
-T --template Only template dotfiles.
|
||||||
-D --showdiff Show a diff before overwriting.
|
-D --showdiff Show a diff before overwriting.
|
||||||
-l --inv-link Invert "link_import_default".
|
|
||||||
-P --show-patch Provide a one-liner to manually patch template.
|
-P --show-patch Provide a one-liner to manually patch template.
|
||||||
-f --force Do not warn if exists.
|
-f --force Do not warn if exists.
|
||||||
-k --key Treat <path> as a dotfile key.
|
-k --key Treat <path> as a dotfile key.
|
||||||
@@ -72,7 +78,6 @@ Options:
|
|||||||
-b --no-banner Do not display the banner.
|
-b --no-banner Do not display the banner.
|
||||||
-v --version Show version.
|
-v --version Show version.
|
||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
|
|
||||||
""".format(BANNER, PROFILE)
|
""".format(BANNER, PROFILE)
|
||||||
|
|
||||||
|
|
||||||
@@ -181,13 +186,12 @@ class Options(AttrMonitor):
|
|||||||
|
|
||||||
# import link default value
|
# import link default value
|
||||||
self.import_link = self.link_import_default
|
self.import_link = self.link_import_default
|
||||||
if self.args['--inv-link']:
|
link = self.args['--link']
|
||||||
if self.import_link == LinkTypes.NOLINK:
|
if link:
|
||||||
self.import_link = LinkTypes.PARENT
|
if link not in OPT_LINK.keys():
|
||||||
elif self.import_link == LinkTypes.PARENT:
|
self.log.err('bad option for --link: {}'.format(link))
|
||||||
self.import_link = LinkTypes.NOLINK
|
sys.exit(USAGE)
|
||||||
elif self.import_link == LinkTypes.CHILDREN:
|
self.import_link = OPT_LINK[link]
|
||||||
self.import_link = LinkTypes.NOLINK
|
|
||||||
|
|
||||||
# "listfiles" specifics
|
# "listfiles" specifics
|
||||||
self.listfiles_templateonly = self.args['--template']
|
self.listfiles_templateonly = self.args['--template']
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def _fake_args():
|
|||||||
args['--force'] = False
|
args['--force'] = False
|
||||||
args['--nodiff'] = False
|
args['--nodiff'] = False
|
||||||
args['--showdiff'] = True
|
args['--showdiff'] = True
|
||||||
args['--inv-link'] = False
|
args['--link'] = 'nolink'
|
||||||
args['--template'] = False
|
args['--template'] = False
|
||||||
args['--temp'] = False
|
args['--temp'] = False
|
||||||
args['<key>'] = []
|
args['<key>'] = []
|
||||||
|
|||||||
@@ -50,17 +50,22 @@ class TestConfig(unittest.TestCase):
|
|||||||
self.assertTrue(conf.dump() != '')
|
self.assertTrue(conf.dump() != '')
|
||||||
|
|
||||||
def test_def_link(self):
|
def test_def_link(self):
|
||||||
self._test_link_import('nolink', LinkTypes.NOLINK, False)
|
self._test_link_import('nolink', LinkTypes.PARENT, 'link')
|
||||||
self._test_link_import('link', LinkTypes.PARENT, False)
|
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
|
||||||
self._test_link_import('nolink', LinkTypes.PARENT, True)
|
self._test_link_import('nolink', LinkTypes.CHILDREN, 'link_children')
|
||||||
self._test_link_import('link', LinkTypes.NOLINK, True)
|
self._test_link_import('link', LinkTypes.PARENT, 'link')
|
||||||
|
self._test_link_import('link', LinkTypes.NOLINK, 'nolink')
|
||||||
|
self._test_link_import('link', LinkTypes.CHILDREN, 'link_children')
|
||||||
|
self._test_link_import('link_children', LinkTypes.PARENT, 'link')
|
||||||
|
self._test_link_import('link_children', LinkTypes.NOLINK, 'nolink')
|
||||||
|
self._test_link_import('link_children', LinkTypes.CHILDREN,
|
||||||
|
'link_children')
|
||||||
self._test_link_import_fail('whatever')
|
self._test_link_import_fail('whatever')
|
||||||
self._test_link_import_fail('link_children')
|
|
||||||
|
|
||||||
@patch('dotdrop.config.open', create=True)
|
@patch('dotdrop.config.open', create=True)
|
||||||
@patch('dotdrop.config.os.path.exists', create=True)
|
@patch('dotdrop.config.os.path.exists', create=True)
|
||||||
def _test_link_import(self, cfgstring, expected,
|
def _test_link_import(self, cfgstring, expected,
|
||||||
invert, mock_exists, mock_open):
|
cliargs, mock_exists, mock_open):
|
||||||
data = '''
|
data = '''
|
||||||
config:
|
config:
|
||||||
backup: true
|
backup: true
|
||||||
@@ -83,8 +88,7 @@ profiles:
|
|||||||
args = _fake_args()
|
args = _fake_args()
|
||||||
args['--profile'] = 'p1'
|
args['--profile'] = 'p1'
|
||||||
args['--cfg'] = 'mocked'
|
args['--cfg'] = 'mocked'
|
||||||
if invert:
|
args['--link'] = cliargs
|
||||||
args['--inv-link'] = True
|
|
||||||
o = Options(args=args)
|
o = Options(args=args)
|
||||||
|
|
||||||
self.assertTrue(o.import_link == expected)
|
self.assertTrue(o.import_link == expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user