Click Components#
The core click components are built to provide required functionality to the Click library which is used for creating commands.
BlockChainParamType#
A click param type to validate and transform the input name for a blockchain and provide a blockcrawler.core.entities.BlockChain value.
Example:
@click.argument("BLOCKCHAIN", type=BlockChainParamType())
HexIntParamType#
A click param type to validate and transform the input hex or int and provide a blockcrawler.core.types.HexInt value.
Example:
@click.argument("HEX_INT", type=HexIntParamType())
AddressParamType#
A click param type to validate and transform the input hex for a blockchain address and provide a blockcrawler.core.entities.Address value.
Example:
@click.argument("ADDRESS", type=AddressParamType())
HexBytesParamType#
A click param type to validate and transform the input hex and provide a hexbytes.HexBytes value.
Example:
@click.argument("HEX_BYTES", type=HexBytesParamType())
Complete Simple Example#
import click
from hexbytes import HexBytes
from blockcrawler.core.click import (
BlockChainParamType,
HexIntParamType,
AddressParamType,
HexBytesParamType,
)
from blockcrawler.core.entities import BlockChain
from blockcrawler.core.types import HexInt, Address
@click.command()
@click.argument("BLOCKCHAIN", type=BlockChainParamType())
@click.argument("HEX_INT", type=HexIntParamType())
@click.argument("ADDRESS", type=AddressParamType())
@click.argument("HEX_BYTES", type=HexBytesParamType())
def run(blockchain: BlockChain, hex_int: HexInt, address: Address, hex_bytes: HexBytes):
print("blockchain:", blockchain)
print("hex_int:", hex_int)
print("address:", address)
print("hex_bytes:", hex_bytes)
if __name__ == "__main__":
run()
Executing the above example will result in something similar to the following being displayed in the console:
Download the example and try it yourself.