import pipes


def as_shell_string(args):
  """Turns the args representing a command into a string for running in a shell.

  The string returned can be copy/pasted and run from a shell. This uses
  pipes.quote to escape the arguments for shell use. Arguments with an equal
  sign, such as flag args, have the values on each side of the equal sign
  escaped separately in order to improve readability.

  Args:
    args: A list of the args used for running the process.
  Returns:
    A string for running the command from a shell.
  """
  quoted_args = []
  for arg in args:
    if '=' in arg:
      flag, value = arg.split('=', 1)
      quoted_args.append(pipes.quote(flag) + '=' + pipes.quote(value))
    else:
      quoted_args.append(pipes.quote(arg))
  return ' '.join(quoted_args)