Skip to content

Commit

Permalink
Updating l2format and examples, doucmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Jul 23, 2023
1 parent 16e5a00 commit a61ef7d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
14 changes: 8 additions & 6 deletions docs/Lama2/docs/explanation/l2format.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Cookie:'sessionid=foo;another-cookie=bar'
```


### Environment Variables: Switch base URL
### Environment Variables

#### API variables can be defined in `apirequest.l2`
Variables are declared within the JS processor block and serve as dynamic placeholders for data used in API requests.
Expand Down Expand Up @@ -109,13 +109,13 @@ Get [Source Files](https://github.com/HexmosTech/Lama2/tree/main/examples/0021_v
#### API environment variables can be defined locally in `l2.env`
L2 provides a convenient way to define environment variables through the l2.env file.
This file is automatically searched for in the present directory,
and its contents are loaded to create a set of variables(local).
and its contents are loaded to create a set of variables (local).

In the `l2.env` file, you can specify environment-specific values for variables used in your L2 scripts, such as URLs, authentication tokens, or any other data that may vary depending on the environment in which the API requests are executed.

![l2.env at API level](l2env.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-1-l2env-adjacent-to-an-api-file)
Go to [Example](../tutorials/examples.md#case-1-l2env-adjacent-to-an-api-file)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0023_l2env_declare)

Expand All @@ -127,17 +127,19 @@ The search for `l2config.env` extends from the present directory up to the root

![l2config.env at Project root level](l2configAtRoot.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-2-root-variables)
Go to [Example](../tutorials/examples.html#case-2-root-variables)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0022_l2config_declare)


#### If `l2config.env`(root) variables are redeclared in `l2.env`(local)
In situations where both root and local variables share the same variable name, the local variable takes precedence over the root variable. This behavior remains consistent, even if both `l2config.env` (root) and `l2.env` (local) files reside in the same directory. The local variable's value will always be considered over the root variable, ensuring that specific configurations defined at the local level effectively override any corresponding settings present in the root file. This approach provides developers with granular control and flexibility in tailoring environment variables to suit specific needs within different parts of the project while maintaining the overall structure and organization of configuration settings.
In situations where both root and local variables share the same variable name, the local variable takes precedence over the root variable. This behavior remains consistent, even if both `l2config.env` (root) and `l2.env` (local) files reside in the same directory.

The local variable's value will always be considered over the root variable, ensuring that specific configurations defined at the local level effectively override any corresponding settings present in the root file. This approach provides developers with granular control and flexibility in tailoring environment variables to suit specific needs within different parts of the project while maintaining the overall structure and organization of configuration settings.

![l2config.env at Project root level](l2envOverideL2config.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-3-override-root-variable-with-local-variable)
Go to [Example](..g/tutorials/examples.html#case-3-override-root-variable-with-local-variable)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local)

Expand Down
36 changes: 32 additions & 4 deletions docs/Lama2/docs/tutorials/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
The `l2` command provides some helpful options for
extension developers. The options are:

1. `--nocolor` or `-n` disables colored output in httpie-go (in CLI);
1. `--output=<target.json` or `-o` writes a structured JSON
1. `--env` or `-e` outputs a JSON of environment variables (in CLI);
2. `--nocolor` or `-n` disables colored output in httpie-go (in CLI);
3. `--output=<target.json` or `-o` writes a structured JSON
output to the target file (without colors). The following is the content
structure:

Expand All @@ -19,13 +20,15 @@ structure:
- `headers`: A string consisting of `HTTP header: Value` pairs separated by newline.
- `body`: A string containing the HTTP response. Usually a JSON or HTML response.


!!! note

Right now, all the three values in the JSON are strings. In the future, we may transform the values further to provide a more parse-friendly structure.

## The Command
## The Commands

Combining the above two options, we get:
### Execute current file
Combining the options `-n` and `-o`, we get:

```bash
l2 -n -o /tmp/lama2.json my_api.l2
Expand All @@ -40,6 +43,31 @@ display the contents to users appropriately. For an
example, see [Lama2 for VSCode](https://github.com/HexmosTech/Lama2Code)
(also see [Marketplace page](https://marketplace.visualstudio.com/items?itemName=hexmos.Lama2)).

### Providing environment variable autocompletion
To obtain a combined JSON representation of environment variables from `l2.env` and `l2config.env`, use option `-e` or `--env`. This will output the result to `stdout`.
```bash
l2 -e /path/to/my_api.l2
```
```json
{
"AHOST": {
"src": "l2env",
"val": "http://127.0.0.1:8000"
},
"BHOST": {
"src": "l2configenv",
"val": "https://httpbin.org"
}
}
```
The extension author can simply read the `stdout` after executing the command, and display the variables to users appropriately.

![l2envvariable variable](l2envvariable.png)

![l2configvariable variable](l2configvariable.png)

Go to [Example](../tutorials/examples.html#case-3-override-root-variable-with-local-variable)

## Syntax Highlighting

The VSCode plugin implements a rudimentary syntax highlighting for `.l2` files. We use [Iro](https://eeyo.io/iro/documentation/) for syntax grammar generation. Find [more details](https://github.com/HexmosTech/Lama2/tree/main/syntax/README.md) if interested.
6 changes: 5 additions & 1 deletion docs/Lama2/docs/tutorials/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ c=d

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0003_comment.l2)

## Environment Variables:
## Environment Variables: Switch base URL
### Case 1: `l2.env` adjacent to an API file

For any given `.l2` file, one can place an `l2.env` file to store relevant variables.
Expand Down Expand Up @@ -139,6 +139,10 @@ ${AHOST}/users

![Override of l2config.env with l2.env variable](l2envOverideL2config.png)

![l2envvariable variable](l2envvariable.png)

![l2configvariable variable](l2configvariable.png)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local)

## Headers
Expand Down
Binary file added docs/Lama2/docs/tutorials/l2configvariable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Lama2/docs/tutorials/l2envvariable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a61ef7d

Please sign in to comment.