In certain situations when working with cli, there are instances in which a text can
be displayed multiple times or a set of validations occuring multiple times. Writing
codes which are recurring multiple times can be a great issue and waste of time which is
against one of the major reasons spoova was developed. In other to lessen this burden,
the Cli makes it possible for us to store recurring functions with a name which can later
be called. The storage and recall of values is handled by the Cli::save()
and Cli::fn()
methods.
save
values that are expected to be used later. These values
can be strings, integers or closure functions. Naturally, every value to be saved must be saved with
a unique id, usually integer. Then the id can then be called later.
Cli::save($id, $value);
where:
$id : a unique id to store value
$value : a value desired to be stored
Cli::fn($id);
where:
$id : storage id of saved value.
Cli::save(1, fn() => Cli::textView('my function 1') );
Cli::fn(1); //prints "my function 1"
Cli::save(1, function(){ Cli::textView('my function 1'); }, true ); Cli::fn(1);
save
method will first execute the closure function once before
storing it. This means that the function will be executed twice, since the Cli::fn()
was also used.