Cli Storage

Introduction

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.

Cli::save()
This method is used to 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.

Syntax: Cli::save()
  Cli::save($id, $value);
    
    where: 

      $id    : a unique id to store value
      $value : a value desired to be stored
    
                                    


Cli::fn()
This method is used to recall a saved value by calling its previous storage id.
Syntax: Cli::fn()
  Cli::fn($id);
    
    where: 

      $id : storage id of saved value.
    
                                    

Example 1: storing and calling a closure function
  Cli::save(1, fn() => Cli::textView('my function 1') );
  
  Cli::fn(1); //prints "my function 1"
                                    


Example 1: storing with an initial execution
  Cli::save(1, function(){
    
      Cli::textView('my function 1');
    
    }, true 
  );
  
  Cli::fn(1);
                                    
In the code above, because a third argument of true was supplied, the 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.