from __future__ import absolute_import, division, print_function, unicode_literals

from echomesh.base import Config
from echomesh.command import Register
from echomesh.util import Log

LOGGER = Log.logger(__name__)

def get_config(_, value, *more):
  errors = []
  successes = []
  for v in (value,) + more:
    try:
      successes.append([v, Config.get(*v.split('.'))])
    except:
      errors.append(v)

  for value, result in successes:
    LOGGER.info('%s=%s', value, result)
  if errors:
    LOGGER.error('Didn\'t understand %s', Join.join_words(errors))

GET_HELP = """
  Prints one or more configuration variables.

Examples:
  config.get speed
  config.get audio.input.enabled audio.output.enabled
"""

Register.register(get_config, 'get', GET_HELP)

@@ -214,40 +214,190 @@
 _)%0A%0A
-def get_config(_, value, *more):
+GET_ARGUMENT_ERROR = %22%22%22%0A%22get%22 needs one or more arguments.%0A%0AExample:%0A  get audio.input.enable%0A%22%22%22%0A%0Adef get_config(_, *items):%0A  if not items:%0A    raise Exception(GET_ARGUMENT_ERROR)
 %0A  e
@@ -439,23 +439,13 @@
  in 
-(value,) + more
+items
 :%0A  

Fix https://github.com/rec/echomesh/issues/324