import shlex


def parse_line(line_or_args):
  """Parse line or list of text into (cmd, rest of args)."""
  if isinstance(line_or_args, list):
    return (line_or_args[0], line_or_args[1:])
  try:
    if " " in line_or_args:
      (cmd, args) = line_or_args.split(maxsplit=1)
      return (cmd, shlex.split(args))
  except ValueError:
    pass
  return (line_or_args.strip(), None)