def _handle_read()

in protool/command_line.py [0:0]


def _handle_read(args: argparse.Namespace) -> int:
    """Handle the read sub command."""

    try:
        value = protool.value_for_key(args.profile, args.key)
    except Exception as ex:
        print(f"Could not read file: {ex}", file=sys.stderr)
        return 1

    regular_types = [str, int, float]
    found_supported_type = False

    for regular_type in regular_types:
        if isinstance(value, regular_type):
            found_supported_type = True
            print(value)
            break

    if not found_supported_type:
        try:
            result = json.dumps(value)
        except Exception:
            print(
                "Unable to serialize values. Please use the XML format instead.",
                file=sys.stderr,
            )
            return 1

        print(result)

    return 0