click_callbacks

callbacks for special parsing of command line inputs

Callbacks By type

File input

file inputs can be given with wildcard expansion (in quotes so that the callback handles) using glob plus the following:

  • [abc] (one of a, b, or c)

  • [!abc] (none of a, b or c)

  • ‘-’ (hyphen) collect the stdin into a temporary file (clasp_tmp*)

  • ~ expands user

callback functions

  • is_file: check if a single path exists (prompts for user input if file not found)

  • are_files: recursively calls parse_file_list and prompts on error

  • is_file_iter: use when multiple=True

  • are_files_iter: use when mulitple=True

  • are_files_or_str: tries to parse as files, then tries split_float, then split_int, then returns string

  • are_files_or_str_iter: use when mulitple=True

String parsing

  • split_str: split with shlex.split

  • split_str_iter: use when multiple=True

  • color_inp: return alpha string, split on whitespace, convert floats and parse tuples on ,

  • char0: return first character

Number parsing

  • tup_int: parses integer tuples from comma/space separated string

  • tup_float: parses float tuples from comma/space separated string

  • split_float: splits list of floats and extends ranges based on : notation

  • split_int: splits list of ints and extends ranges based on : notation

clasp.click_callbacks.callback_error(s, param, example)[source]

standard error message for exceptions raised during argument parsing

used by custom callback functions raises ClickException

Parameters
  • s (value) –

  • param (click.core.Option) –

  • example (example of valid entry format) –

clasp.click_callbacks.is_file(ctx, param, s)[source]

checks input file string with recursive prompt

use os.environ[‘CLASP_PIPE’] = ‘1’ in parent script or set CLASP_PIPE=1 to disable prompt and avoid hanging process

clasp.click_callbacks.char0(ctx, param, s)[source]
clasp.click_callbacks.are_files(ctx, param, s, prompt=True)[source]

checks input file list string with recursive prompt

use os.environ[‘CLASP_PIPE’] = ‘1’ in parent script or set CLASP_PIPE=1 to disable prompt and avoid hanging process

clasp.click_callbacks.are_valid_paths(ctx, param, s)[source]

checks input file list

clasp.click_callbacks.is_files_iter(ctx, param, s)[source]

calls are_files for each item in iterable s use with multiple=True

clasp.click_callbacks.are_files_iter(ctx, param, s, prompt=True)[source]

calls are_files for each item in iterable s use with multiple=True

clasp.click_callbacks.are_files_or_str(ctx, param, s)[source]

tries are_files for each item then split_str

clasp.click_callbacks.are_files_or_str_iter(ctx, param, s)[source]

tries are_files then split_str use with multiple=True

clasp.click_callbacks.split_str(ctx, param, s)[source]

splits space seperated string

clasp.click_callbacks.split_str_iter(ctx, param, s)[source]

calls are_files for each item in iterable s use with multiple=True

clasp.click_callbacks.color_inp(ctx, param, s)[source]

parses color tuple from comma/space seperated string or cmap name

clasp.click_callbacks.tup_int(ctx, param, s, recurs=False)[source]

parses integer or len 2 tuples from comma/space separated string with range : notation

clasp.click_callbacks.int_tups(ctx, param, s)[source]

parses integer tuples from comma/space separated string

clasp.click_callbacks.tup_float(ctx, param, s)[source]

parses float tuples from comma/space separated string

clasp.click_callbacks.tup_list(ctx, param, s)[source]

convert tuple to list

clasp.click_callbacks.split_float(ctx, param, s)[source]

splits list of floats and extends ranges based on : notation

clasp.click_callbacks.split_int(ctx, param, s)[source]

splits list of ints and extends ranges based on : notation

clasp.click_callbacks.data_stream(ctx, param, s)[source]
clasp.click_callbacks.tmp_stdin(ctx)[source]

read stdin into temporary file

use ctx.resilient_parsing=True to pass “-” directly

clasp.click_callbacks.parse_file_list(ctx, s, valid=False)[source]

parses list of files using glob expansion