github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/config.md (about)

     1  # `config`
     2  
     3  > Query or define Murex runtime settings
     4  
     5  ## Description
     6  
     7  Rather than Murex runtime settings being definable via obscure environmental
     8  variables, Murex instead supports a registry of config defined via the
     9  `config` command. This means any preferences and/or runtime config becomes
    10  centralised and discoverable.
    11  
    12  ## Usage
    13  
    14  List all settings:
    15  
    16  ```
    17  config -> <stdout>
    18  ```
    19  
    20  Get a setting:
    21  
    22  ```
    23  config get app key -> <stdout>
    24  ```
    25  
    26  Set a setting:
    27  
    28  ```
    29  config set app key value
    30  
    31  <stdin> -> config set app key
    32  
    33  config eval app key { -> code-block }
    34  ```
    35  
    36  Define a new config setting:
    37  
    38  ```
    39  config define app key { json }
    40  ```
    41  
    42  Reset a setting to it's default value:
    43  
    44  ```
    45  !config app key
    46  
    47  config default app key
    48  ```
    49  
    50  ## Examples
    51  
    52  Using `eval` to append to an array (in this instance, adding a function
    53  name to the list of "safe" commands)
    54  
    55  ```
    56  » function foobar { -> match foobar }
    57  » config eval shell safe-commands { -> append foobar }
    58  ```
    59  
    60  ## Detail
    61  
    62  With regards to `config`, the following terms are applied:
    63  
    64  ### app
    65  
    66  This refers to a grouped category of settings. For example the name of a built
    67  in.
    68      
    69  Other app names include
    70  
    71  * `shell`: for "global" (system wide) Murex settings
    72  * `proc`: for scoped Murex settings
    73  * `http`: for settings that are applied to any processes which use the builtin
    74      HTTP user agent (eg `open`, `get`, `getfile`, `post`)
    75  * `test`: settings for Murex's test frameworks
    76  * `index`: settings for `[` (index)
    77  
    78  ### key
    79  
    80  This refers to the config setting itself. For example the "app" might be `http`
    81  but the "key" might be `timeout` - where the "key", in this instance, holds the
    82  value for how long any HTTP user agents might wait before timing out.
    83  
    84  ### value
    85  
    86  Value is the actual value of a setting. So the value for "app": `http`, "key":
    87  `timeout` might be `10`. eg
    88  
    89  ```
    90  » config get http timeout
    91  10
    92  ```
    93  
    94  ### scope
    95  
    96  Settings in `config`, by default, are scoped per function and module. Any
    97  functions called will inherit the settings of it's caller parent. However any
    98  child functions that then change the settings will only change settings for it's
    99  own function and not the parent caller.
   100  
   101  Please note that `config` settings are scoped differently to local variables.
   102  
   103  ### global
   104  
   105  Global settings defined inside a function will affect settings queried inside
   106  another executing function (same concept as global variables).
   107  
   108  ## Directives
   109  
   110  The directives for `config define` are listed below.
   111  
   112  <div id="toc">
   113  
   114  - [DataType](#datatype)
   115  - [Description"](#description)
   116  - [Global](#global)
   117  - [Default](#default)
   118  - [Options](#options)
   119  - [Dynamic](#dynamic)
   120    - [Dynamic Read](#dynamic-read)
   121    - [Dynamic Write](#dynamic-write)
   122  
   123  </div>
   124  
   125  
   126  ```
   127  "DirectiveName": json data-type (default value)
   128  ```
   129  
   130  Where "default value" is what will be auto-populated if you don't include that
   131  directive (or "required" if the directive must be included).
   132  
   133  ### DataType
   134  
   135  > Value: `str` (required)
   136  
   137  This is the Murex data-type for the value.
   138  
   139  ### Description"
   140  
   141  > Value: `str` (required)
   142  
   143  Description is a required field to force developers into writing meaning hints
   144  enabling the discoverability of settings within Murex.
   145  
   146  ### Global
   147  
   148  > Value: `bool` (default: `false`)
   149  
   150  This defines whether this setting is global or scoped.
   151  
   152  All **Dynamic** settings _must_ also be **Global**. This is because **Dynamic**
   153  settings rely on a state that likely isn't scoped (eg the contents of a config
   154  file).
   155  
   156  ### Default
   157  
   158  > Value: any (required)
   159  
   160  This is the initialized and default value.
   161  
   162  ### Options
   163  
   164  > Value: array (default: `null`)
   165  
   166  Some suggested options (if known) to provide as autocompletion suggestions in
   167  the interactive command line.
   168  
   169  ### Dynamic
   170  
   171  > Value: map of strings (default: `null`)
   172  
   173  Only use this if config options need to be more than just static values stored
   174  inside Murex's runtime. Using **Dynamic** means `autocomplete get app key`
   175  and `autocomplete set app key value` will spawn off a subshell running a code
   176  block defined from the `Read` and `Write` mapped values. eg
   177  
   178  ```
   179  # Create the example config file
   180  out "this is the default value" |> example.conf
   181  
   182  config define example test5 %{
   183      Description: This is only an example
   184      DataType: str
   185      Global: true
   186      Dynamic: {
   187          Read: '{
   188              open example.conf
   189          }'
   190          Write: '{
   191              |> example.conf
   192          }'
   193      },
   194      
   195      # read the config file to get the default value
   196      Default: ${open example.conf}
   197  }
   198  ```
   199  
   200  It's also worth noting the different syntax between **Read** and **Default**.
   201  The **Read** code block is being executed when the **Read** directive is being
   202  requested, whereas the **Default** code block is being executed when the JSON
   203  is being read.
   204  
   205  In technical terms, the **Default** code block is being executed by Murex 
   206  when `config define` is getting executed where as the **Read** and **Write**
   207  code blocks are getting stored as a JSON string and then executed only when
   208  those hooks are getting triggered.
   209  
   210  #### Dynamic Read
   211  
   212  > Value: `str` (default: empty)
   213  
   214  This is executed when `autocomplete get app key` is ran. The STDOUT of the code
   215  block is the setting's value.
   216  
   217  #### Dynamic Write
   218  
   219  > Value: `str` (default: empty)
   220  
   221  This is executed when `autocomplete` is setting a value (eg `set`, `default`,
   222  `eval`). is ran. The STDIN of the code block is the new value.
   223  
   224  ## Synonyms
   225  
   226  * `config`
   227  * `!config`
   228  
   229  
   230  ## See Also
   231  
   232  * [`%{}` Create Map](../parser/create-object.md):
   233    Quickly generate objects and maps
   234  * [`[ Index ]`](../parser/item-index.md):
   235    Outputs an element from an array, map or table
   236  * [`[[ Element ]]`](../parser/element.md):
   237    Outputs an element from a nested structure
   238  * [`append`](../commands/append.md):
   239    Add data to the end of an array
   240  * [`event`](../commands/event.md):
   241    Event driven programming for shell scripts
   242  * [`function`](../commands/function.md):
   243    Define a function block
   244  * [`get`](../commands/get.md):
   245    Makes a standard HTTP request and returns the result as a JSON object
   246  * [`getfile`](../commands/getfile.md):
   247    Makes a standard HTTP request and return the contents as Murex-aware data type for passing along Murex pipelines.
   248  * [`match`](../commands/match.md):
   249    Match an exact value in an array
   250  * [`open`](../commands/open.md):
   251    Open a file with a preferred handler
   252  * [`post`](../commands/post.md):
   253    HTTP POST request with a JSON-parsable return
   254  * [`runtime`](../commands/runtime.md):
   255    Returns runtime information on the internal state of Murex
   256  
   257  <hr/>
   258  
   259  This document was generated from [builtins/core/config/config_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/config/config_doc.yaml).