Improve CLI

This commit is contained in:
Markus Unterwaditzer 2014-03-13 20:15:31 +01:00
parent 8db16454f8
commit 18fe8096f5

View file

@ -101,6 +101,33 @@ def main():
_main(env, cfg) _main(env, cfg)
def parse_pairs_args(pairs_args, all_pairs):
if not pairs_args:
pairs_args = list(all_pairs)
for pair_and_collection in pairs_args:
pair, collection = pair_and_collection, None
if '/' in pair:
pair, collection = pair.split('/')
try:
a_name, b_name, pair_options, storage_defaults = \
all_pairs[pair]
except KeyError:
cli_logger.critical('Pair not found: {}'.format(pair))
cli_logger.critical('These are the pairs found: ')
cli_logger.critical(list(all_pairs))
sys.exit(1)
if collection is None:
collections = [x.strip() for x in
pair_options.get('collections', '').split(',')]
else:
collections = [collection]
for c in collections:
yield pair, c
def _main(env, file_cfg): def _main(env, file_cfg):
general, all_pairs, all_storages = file_cfg general, all_pairs, all_storages = file_cfg
app = argvard.Argvard() app = argvard.Argvard()
@ -124,23 +151,20 @@ def _main(env, file_cfg):
@sync_command.main('[pairs...]') @sync_command.main('[pairs...]')
def sync_main(context, pairs=None): def sync_main(context, pairs=None):
'''Syncronize the given pairs. If no pairs are given, all will be '''
synchronized.''' Syncronize the given pairs. If no pairs are given, all will be
if pairs is None: synchronized.
pairs = list(all_pairs)
Examples:
`vdirsyncer sync` will sync everything configured.
`vdirsyncer sync bob frank` will sync the pairs "bob" and "frank".
`vdirsyncer sync bob/first_collection` will sync "first_collection"
from the pair "bob".
'''
actions = [] actions = []
for pair_name in pairs: for pair_name, collection in parse_pairs_args(pairs, all_pairs):
try:
a_name, b_name, pair_options, storage_defaults = \ a_name, b_name, pair_options, storage_defaults = \
all_pairs[pair_name] all_pairs[pair_name]
except KeyError:
cli_logger.critical('Pair not found: {}'.format(pair_name))
cli_logger.critical('These are the pairs found: ')
cli_logger.critical(list(all_pairs))
sys.exit(1)
collections = pair_options.get('collections', '').split(',')
for collection in collections:
collection = collection.strip()
if collection: if collection:
storage_defaults['collection'] = collection storage_defaults['collection'] = collection
config_a = dict(storage_defaults) config_a = dict(storage_defaults)