def run_command(command, args, cwd):
  """Runs a command with the given context.

  Args:
    command: ManageCommand to run.
    args: Arguments, with the app and command name stripped.
    cwd: Current working directory.

  Returns:
    0 if the command succeeded and non-zero otherwise.

  Raises:
    ValueError: The command could not be found or was not specified.
  """
  parser = command.create_argument_parser()
  parsed_args = parser.parse_args(args)
  return command.execute(parsed_args, cwd)