code: def list_available_cards(
      ctx,
      pathspec,
      card_paths,
      card_datastore,
      command="view",
      show_list_as_json=False,
      list_many=False,
      file=None,
  ):
      # pathspec is full pathspec.
      # todo : create nice response messages on the CLI for cards which were found.
      scriptname = ctx.obj.flow.script_name
      path_tuples = card_datastore.get_card_names(card_paths)
      if show_list_as_json:
          json_arr = [
              dict(
                  id=tup.id,
                  hash=tup.hash,
                  type=tup.type,
                  filename=tup.filename,
              )
              for tup in path_tuples
          ]
          if not list_many:
              # This means that `list_available_cards` is being called once.
              # So we can directly dump the file
              dump_dict = dict(pathspec=pathspec, cards=json_arr)
              if file:
                  with open(file, "w") as f:
                      json.dump(dump_dict, f)
              else:
                  ctx.obj.echo_always(
                      json.dumps(dump_dict, indent=4), err=False
                  )
          # if you have to list many in json format then return
          return dict(pathspec=pathspec, cards=json_arr)
  
      if list_many:
          ctx.obj.echo(
              "\tTask: %s" % pathspec.split("/")[-1], fg="green"
          )
      else:
          ctx.obj.echo(
              "Found %d card matching for your query..."
              % len(path_tuples),
              fg="green",
          )
      task_pathspec = "/".join(pathspec.split("/")[1:])
      card_list = []
      for path_tuple, file_path in zip(path_tuples, card_paths):
          full_pth = card_datastore.create_full_path(file_path)
          cpr = """
          Card Id: %s
          Card Type: %s
          Card Hash: %s 
          Card Path: %s
          """ % (
              path_tuple.id,
              path_tuple.type,
              path_tuple.hash,
              full_pth,
          )
          card_list.append(cpr)
  
      random_idx = (
          0
          if len(path_tuples) == 1
          else random.randint(0, len(path_tuples) - 1)
      )
      _, randhash, _, file_name = path_tuples[random_idx]
      join_char = "\n\t"
      ctx.obj.echo(join_char.join([""] + card_list) + "\n", fg="blue")
  
      if command is not None:
          ctx.obj.echo(
              "\n\tExample access from CLI via: \n\t %s\n"
              % make_command(
                  scriptname,
                  task_pathspec,
                  command=command,
                  hash=randhash[:NUM_SHORT_HASH_CHARS],
              ),
              fg="yellow",
          )
  
imports: from metaflow.client import Task
  from metaflow import JSONType, namespace
  from metaflow.util import resolve_identity
  from metaflow.exception import CommandException, MetaflowNotFound, MetaflowNamespaceMismatch
  import webbrowser
  import re
  from metaflow._vendor import click
  import os
  import json
  import uuid
  import signal
  import random
  from contextlib import contextmanager
  from functools import wraps
  from metaflow.exception import MetaflowNamespaceMismatch
  from .card_datastore import CardDatastore, NUM_SHORT_HASH_CHARS
  from .exception import CardClassFoundException, IncorrectCardArgsException, UnrenderableCardException, CardNotPresentException, TaskNotFoundException
  import traceback
  from collections import namedtuple
  from .card_resolver import resolve_paths_from_task, resumed_info
label_desc: Use image node_id 6 for calling a global function with example usage: list_available_cards(ctx, pathspec, card_paths, card_datastore, command, show_list_as_json, list_many, file) and returns: dict