Gathering predefined options is useful when executing an MBFL script as subprocess for an MBFL script: we can hand the subprocess the same options that were given to the process, or maybe change them. The following functions are used to gather the required options:
mbfl_option_verbose mbfl_option_verbose_program mbfl_option_debug mbfl_option_show_program mbfl_option_test mbfl_option_interactive mbfl_option_null mbfl_option_encoded_args
Append to the data variable whose name is _RV a list of MBFL command–line options reflecting the current MBFL options state. Assuming no predefined options were given on the command line:
mbfl_declare_varref(FLAGS) mbfl_set_option_verbose mbfl_set_option_test mbfl_getopts_gather_mbfl_options_var mbfl_datavar(FLAGS) "$FLAGS" ⇒ '--verbose --test'
We can test how this works with:
{
mbfl_declare_varref(FLAGS)
local -a ARGV1=('--show-program' '--verbose-program')
local -i ARGC1=mbfl_slots_number(ARGV1)
local -i ARG1ST=0
local -a ARGV
local -i ARGC=0
mbfl_getopts_reset
mbfl_getopts_parse
FLAGS='-a -b -c'
mbfl_getopts_gather_mbfl_options_var mbfl_datavar(FLAGS)
mbfl_string_equal "$FLAGS" '-a -b -c --verbose-program --show-program'
}
⇒ 0
Append to the pairs in the indexed array variable whose name is _RV_ARRAY a list of MBFL command–line options reflecting the current MBFL options state. Assuming no predefined options were given on the command line:
mbfl_declare_index_array_varref(FLAGS_ARRY) mbfl_set_option_verbose mbfl_set_option_test mbfl_getopts_gather_mbfl_options_array mbfl_datavar(FLAGS_ARRY) mbfl_slot_ref(FLAGS_ARRY, 0) ⇒ --verbose mbfl_slot_ref(FLAGS_ARRY, 1) ⇒ --test
We can test how this works with:
{
mbfl_declare_index_array_varref(FLAGS_ARRY, ('-a' '-b' '-c'))
local -a ARGV1=('--show-program' '--verbose-program')
local -i ARGC1=mbfl_slots_number(ARGV1)
local -i ARG1ST=0
local -a ARGV
local -i ARGC=0
mbfl_getopts_reset
mbfl_getopts_parse
FLAGS='-a -b -c'
mbfl_getopts_gather_mbfl_options_array mbfl_datavar(FLAGS_ARRY)
mbfl_slot_ref(FLAGS_ARRY, 0) ⇒ -a
mbfl_slot_ref(FLAGS_ARRY, 1) ⇒ -b
mbfl_slot_ref(FLAGS_ARRY, 2) ⇒ -c
mbfl_slot_ref(FLAGS_ARRY, 3) ⇒ --verbose-program
mbfl_slot_ref(FLAGS_ARRY, 4) ⇒ --show-program
}
Once we have built the array, we can extract its values with:
mbfl_slots_qvalues(FLAGS_ARRY)
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.