{"id":20804358,"url":"https://github.com/nbittich/adana","last_synced_at":"2025-04-13T06:28:31.374Z","repository":{"id":37828491,"uuid":"493395170","full_name":"nbittich/adana","owner":"nbittich","description":"repl / scripting language / namespaced command line aliases","archived":false,"fork":false,"pushed_at":"2025-03-03T04:41:54.000Z","size":14712,"stargazers_count":68,"open_issues_count":4,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T05:07:51.098Z","etag":null,"topics":["alias-management","interpreter","language","namespacing","programming-language","repl","rust","scripting","wasm"],"latest_commit_sha":null,"homepage":"https://nbittich.github.io/adana/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nbittich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-17T19:56:07.000Z","updated_at":"2025-03-03T04:41:57.000Z","dependencies_parsed_at":"2024-04-17T18:56:46.939Z","dependency_job_id":"314daf4d-5094-4107-ab7f-1d5fd503433a","html_url":"https://github.com/nbittich/adana","commit_stats":{"total_commits":298,"total_committers":6,"mean_commits":"49.666666666666664","dds":"0.21476510067114096","last_synced_commit":"51eab26d24ce907ab10c23f3764b8de8e45678ef"},"previous_names":["nbittich/karsher"],"tags_count":78,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbittich%2Fadana","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbittich%2Fadana/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbittich%2Fadana/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbittich%2Fadana/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nbittich","download_url":"https://codeload.github.com/nbittich/adana/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248310555,"owners_count":21082444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alias-management","interpreter","language","namespacing","programming-language","repl","rust","scripting","wasm"],"created_at":"2024-11-17T19:08:54.045Z","updated_at":"2025-04-13T06:28:31.346Z","avatar_url":"https://github.com/nbittich.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adana\n\nScripting programming language, repl and namespaced aliases for commands.\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [Installation](#installation)\n3. [Programming language](#programming-language)\n   - [Getting started](#getting-started)\n   - [Comments](#comments)\n   - [Multiline](#multiline)\n   - [F-Strings](#f-strings)\n   - [Operators and constants](#operators-and-constants)\n   - [Variable definition](#variable-definition)\n   - [Memory Management](#memory-management)\n   - [Plugins](#plugins)\n   - [Standard Library](#standard-library)\n   - [Loops](#loops)\n   - [Ranges](#ranges)\n   - [Conditions](#conditions)\n   - [Types](#types)\n   - [Structs](#structs)\n   - [Manipulate arrays](#manipulate-arrays)\n   - [Functions](#functions)\n   - [Include a script file](#include-a-script-file)\n   - [Builtin functions](#builtin-functions)\n4. [Namespaced aliases](#namespaced-aliases)\n   - [Introduction](#namespaced-aliases)\n   - [Try it](#try-it)\n   - [Available commands](#available-commands)\n   - [Shortcuts](#shortcuts)\n   - [Environment variables](#environment-variables)\n   - [Arguments](#arguments)\n\n\u003chr\u003e\n\n## Introduction\n\nThis project started as a way to put into practice what I learned while reading the Rust programming language book.\n\nIt includes features that I find useful, such as a REPL, a calculator,\na scripting language, and a way to store, execute, and load command-line aliases based on the project I'm working on.\n\nBest practices and performance optimization were not a priority, so the code may not be the cleanest or most optimized.\n\nIf you would like to contribute, your pull request would be welcome.\n\n### Where the name comes from?\n\nMy favorite dish 😋\n\n![image](https://github.com/nbittich/adana/assets/21688838/842c98ca-2c92-4452-93cc-7412685a7a3e)\n\n\u003chr\u003e\n\n## Installation\n\n1. Docker\n   - From the docker hub:\n     - `docker run -it nbittich/adana # latest from master`\n     - `docker run -it nbittich/adana:v0.18.6 # latest release`\n   - Manually:\n     - clone the repo\n     - build the docker image: `docker build -t adana .`\n     - `docker run -it adana`\n2. Cargo\n   - From crate.io:\n     - `cargo install adana`\n     - `adana`\n   - Manually:\n     - `cargo build --release`\n     - `./target/release/adana`\n3. WASM Playground\n   - Try it out at https://nbittich.github.io/adana\n\n\u003chr\u003e\n\n## Programming language\n\n### Getting Started\n\nFirst, we start with the traditional hello world:\n\n```python\n println(\"hello world!\") # prints hello world\n```\n\nIn the repl, you could also simply write:\n\n```python\n \"hello world!\" # prints hello world\n```\n\n\u003chr\u003e\n\n### Comments\n\nComments are defined like in python, starting with `#`.\nYou can put them after the last statement or before any useful code, for example:\n\n```python\n # to go to the next line in the repl, press CTRL+x\n\n # this will be ignored by the repl\n\n println(\"hello world!\") # this is also ok\n```\n\n\u003chr\u003e\n\n### Multiline\n\nSemicolons are not needed, if you need multiline statements, you can use a multiline block:\n\n```python\nfancy_string = multiline {\n    \"this string\\n\" +\n    \"\\tis\\n\" +\n    \"\\t\\ton several\\n\" +\n    \"lines\\n\"\n}\n```\n\nMultiline is useful when you want to process different instructions in several lines:\n\n```python\ncomplex_math_stuff = multiline {\n    1 *2\n    + 5 *sqrt(2) / 2.\n    + 300 / 3\n    * 400 % 2 - (1 * 10^3)\n}\n```\n\n\u003chr\u003e\n\n### F-Strings\n\nFor more complex strings, you can use string blocks / F-Strings.\nYou can define them using the java syntax:\n\n```java\nblock_string= \"\"\"Hello world\nI hope you are well.\nThis is a string block. you can use stuff like \"string\"\nthere, nothing will stop you\"\"\"\n```\n\nLike in javascript, you can embed expressions to an f-string:\n\n```javascript\nperson = struct {\n            name  : \"nordine\",\n            wasup : (age) =\u003e {\n                if (age \u003e 30) {\n                    \"you are old!\"\n                } else {\n                    \"you are young!\"\n                }\n            },\n            age  : 34\n        }\n\ns1 = \"\"\"Hello ${person.name}!\nYou are ${person.age} years old.\n${person.wasup(person.age)}\"\"\"\n```\n\n\u003chr\u003e\n\n### Operators and constants\n\nThere are 22 operators \u0026 3 constants:\n\n| **operator** | **description**  |\n| ------------ | ---------------- |\n| `+`          | add              |\n| `-`          | subtract         |\n| `/`          | divide           |\n| `*`          | multiply         |\n| `%`          | modulo           |\n| `^`          | pow              |\n| `²`          | pow 2            |\n| `³`          | pow 3            |\n| `\u003c`          | less than        |\n| `\u003e`          | greater than     |\n| `\u003c=`         | less or equal    |\n| `\u003e=`         | greater or equal |\n| `\u0026\u0026`         | and              |\n| `\\|\\|`       | or               |\n| `\\|`         | bitwise or       |\n| `~`          | bitwise not      |\n| `@`          | bitwise and      |\n| `$`          | bitwise xor      |\n| `\u003c\u003c`         | bitwise lshift   |\n| `\u003e\u003e`         | bitwise rshift   |\n| `==`         | equal            |\n| `()`         | parenthesis      |\n\n| **constant** | **description** |\n| ------------ | --------------- |\n| `π`          | PI number       |\n| `γ`          | EULER number    |\n| `τ`          | TAU number      |\n\nExample:\n\n```python\n 5 + 5 # 10\n 5 + 5.5 # 10.5\n 5 / 5 # 1\n 5 / 6 # 0\n 5 / 6. # 0.8333333333333334 -- we force it to make a float division by adding \".\"\n 5 % 6 # 5 -- modulo on int\n 5 % 4.1 # 0.9000000000000004 modulo on double\n 5 ^ 5 # 3125\n 5 * 5 # 25\n 5 * 5.1 # 25.5\n 5 * (5+ 1/ (3.1 ^2) * 9) ^3. # 1046.084549281999\n 2² # 4\n 2³ # 8\n```\n\nYou can apply an operator before re-assigning a variable, like:\n\n```python\nx =2\nx+=1 # 3\nx-=2 # 1\nx*=4 # 4\nx%=3 # 1\nx/=0.5 # 2\n```\n\nIt is legal in some circumstances to use the multiply operator implicitly.\nIt will only work when there is no space between a number (int, decimal) and a variable name.\n\nExample:\n\n```python\nx=2\n3x²+2x== x*(3x+2) # true\ny=0.5x # 1\n```\n\n\u003chr\u003e\n\n### Variable definition\n\nTo define a variable, simply type the name of the variable followed by \"=\".\nVariable must always start with a letter and can have numerics or \"\\_\" in it.\nAdd and assign(+=), subtract and assign (-=), etc are also supported.\n\n```python\n vat = 1.21 # 1.21\n sub_total1 = 10000\n total = vat * sub_total1 # 12100\n sub_total2 = 500 * vat # 605\n sub_total1 = sub_total1 + sub_total2 # 10605\n```\n\nIt could be simplified as such:\n\n```python\n vat = 1.21 # 1.21\n sub_total1 = 10000\n total = vat * sub_total1 # 12100\n sub_total2 = 500 * vat # 605\n sub_total1 += sub_total2 # 10605\n```\n\nIt's also possible to use the special variable name `_` to notify the language that this value\nis not used and doesn't have to be stored in context:\n\n```python\n_ = 1\n\nfor _, n in 1..3 {\n   println(n)\n}\n\n_ = struct {\n   _: \"I will not be stored!\",\n   x: 39\n}\n```\n\n\u003chr\u003e\n\n### Memory Management\n\nBy default, everything is cloned. As a hobby project, this was a simple way to achieve\nmore and have fun.\n\nNow that enough features have been built, an attempt to implement automatic-ish\nreference counting has started.\n\nThis is highly experimental and a partial or full rewrite of the ast / parser may\nbe needed to implement it properly. To keep the fun working on this, it is not a priority\nfor now.\n\nYou can define a reference as such:\n\n```go\nx = 100\ny = \u0026x # y points to x, no clone\np = 0\nfor _ in 0..\u0026x {\n  p = p+1\n}\n```\n\n```go\nx = 99\ny = \u0026x\nx = 100 # now y == 100\n```\n\n\u003chr\u003e\n\n### Plugins\n\nIt is possible to load plugins written in Rust dynamically.\nBecause [Rust doesn't have a stable ABI yet](https://www.reddit.com/r/rust/comments/ss2p6c/what_does_it_mean_when_people_say_that_rust_does/), the plugin must be built with the same version that\nwas used to build adana.\n\nThe Rust version is specified when running the repl.\n\nTo load a library dynamically, you can either specify a relative path, or an\nabsolute path. In case of a relative path, it should be relative to the\nshared lib path (by default: `$HOME/.local/share/adana/db`).\n\nYou can override this by providing a path when starting the repl (e.g: `adana -slp /tmp`).\n\nIf the path is a directory, it will try to build it using `cargo`, so you\nneed to have Rust installed on your machine.\n\nIf it is an `.so` file, it will automatically load it.\n\nAn example of plugin can be found in this repo (`dynamic_lib/example_lib_src`).\n\nFor example:\n\n- Copy the `.so` file in tmp: `cp dynamic_lib/libplugin_example.so /tmp/`\n- Run and override the lib path: `adana -slp /tmp`\n- Execute the following:\n\n```python\n     lib = require(\"libplugin_example.so\")\n     text = lib.hello(\"Nordine\", \"la\", \"forme?\")\n```\n\nOr in one line:\n\n```python\n   text = require(\"libplugin_example.so\").hello(\"Nordine\", \"la\", \"forme?\")\n```\n\n\u003chr\u003e\n\n### Standard Library\n\nA basic standard library exists [here](https://github.com/nbittich/adana-std).\n\nYou can use it in this way:\n\n```\nfs = require(\"@std/fs\")\nfs.api_description() # description of the api\n```\n\nIf it is not installed yet, you will see instructions on how to install it, e.g:\n\n```\n[rust~/toyprograms/adana(master)] fs = require(\"@std/fs\")\nstd lib doesn't exist: \"/home/nbittich/.local/share/adana/lib/adana-std/fs.so\".\n\nTry to install it like so:\n    - wget -P /tmp https://github.com/nbittich/adana-std/releases/download/0.18.6/adana-std.tar.gz\n    - mkdir -p /home/nbittich/.local/share/adana/lib/adana-std \u0026\u0026 tar xvzf /tmp/adana-std.tar.gz \\\n            -C /home/nbittich/.local/share/adana/lib/adana-std\n```\n\n### Loops\n\nThere are two loops, the while loop and the for-each loop.\nThe while loop looks like the one in C, while the for-each loop is a little bit more\nmodern.\n\nFor-each loop \u0026 while loop don't require parenthesizes.\nYou can only iterate over structs, strings and arrays.\n\n```C\ncount = 0\n\nwhile(count \u003c 10) {\n    println(count)\n    count = count + 1\n}\n```\n\n```\n# also valid\nwhile count \u003c 10 {\n    println(count)\n    count = count + 1\n}\n```\n\n```javascript\nfor n in [1,2,3] {\n   println(n)\n}\n```\n\nYou have access to the current index in a for-each:\n\n```javascript\nfor index, n in [1, 2, 3] {\n    println(\"index: \" + index + \" value: \" + n)\n}\n```\n\nIt is also possible to use the for-each loop with a string:\n\n```javascript\nfor i, letter in \"hello\" {\n  println(i)\n}\n```\n\nIn the case of a struct, the variable will be an entry (a struct with key/value)\n\n```javascript\ns = struct {\n    name: \"nordine\",\n    age: 34,\n    members: [\"natalie\", \"roger\",\"fred\"]\n}\n\nfor  id, entry in s {\n     println(\"Id: \"+id +\" Key: \"+entry.key + \" Value: \" + to_string(entry.value))\n}\n```\n\nParenthesizes are optional for for-each:\n\n```javascript\narr = [1,2,3,4]\ntotal = 0\nidx_total = 0\nfor (index,a in arr) {\n total = total + a\n idx_total = idx_total + index\n}\n```\n\nYou can break if you match a certain condition within a while:\n\n```C\nwhile count \u003c 10 {\n     println(count)\n     count = count + 1\n     if(count % 3 ==0) {\n        break\n     }\n}\n```\n\n\u003chr\u003e\n\n### Ranges\n\nIt is possible to define a range like so \"start..end\" (end exclusive),\nor \"start..=end\" (end inclusive):\n\n```javascript\nx = 0..10 # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\nx = 0..=10 # [0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\nfor i in 1..=10 {\n  println(\"print 10 times this message\")\n}\n```\n\n\u003chr\u003e\n\n### Conditions\n\nSame as C but parenthesizes are optional:\n\n```C\nif age \u003e 12  {\n    println(\"age \u003e 12\")\n} else if age \u003c 9 {\n    println(\"age \u003c 9\")\n} else {\n    println(\"dunno\")\n}\n```\n\n\u003chr\u003e\n\n### Types\n\nThere is no type-checking in the language. You can add a string to an array, nothing will stop you!\n\nIn some cases though, you might get an error.\n\nBelow, is a list of types and how you declare them. You can also define your structure.\n\n| **type** | **examples**                                                                                     |\n| -------- | ------------------------------------------------------------------------------------------------ |\n| null     | `null`                                                                                           |\n| bool     | `true` / `false`                                                                                 |\n| int      | `5000`                                                                                           |\n| u8       | `5`                                                                                              |\n| i8       | `-5`                                                                                             |\n| double   | `12.` / `12.2`                                                                                   |\n| string   | `\"hello\"`                                                                                        |\n| array    | `[1,2,\"3\", true]`                                                                                |\n| function | `() =\u003e {\"hello\"}` \u003cbr\u003e `(name) =\u003e {\"hello\" + name}` \u003cbr\u003e `(n) =\u003e {`\u003cbr\u003e\u0026emsp; `\"hello\"`\u003cbr\u003e`  }` |\n| struct   | `struct {x: 8, y: ()=\u003e {println(\"hello!\")}}`                                                     |\n| error    | `make_err(\"could not process...\")`                                                               |\n\n\u003chr\u003e\n\n### Structs\n\nYou can define structs. Structs are a way of grouping related variables or functions together.\nYou can define function variables within a struct, but you cannot update the members of the function from within\nthe struct (there is no `self` or `this`).\n\nThe comma is required to separate each member, but not for the latest one.\n\nExample of defining a struct:\n\n```javascript\nperson = struct {\n    name: \"hello\",\n    age: 20,\n    headers: struct {\n      \"Content-Type\": \"application/json\"\n    }\n}\n\nperson_service = struct {\n    say_hi: (person) =\u003e { println(\"hi \" + person.name) },\n    check_age: (person) =\u003e {\n             if (person.age \u003c 18) {\n                 println(\"you are too young\")\n             } else {\n                 println(\"you are too old\")\n             }\n    }\n}\n\nperson_service.check_age(person)\n\n```\n\nYou can access a struct in two ways:\n\n```javascript\nname = person[\"name\"] # name contains \"hello\"\nprintln(person[\"age\"])\n\nage=person.age # age contains \"age\"\nprintln(person.age)\n```\n\n### Manipulate arrays\n\nArrays are declared like in javascript but are \"immutable\". After declaration, you cannot (yet) push\nnew data in them. to do that, you have to concatenate them with another array using the \"+\" operator.\n\n```python\n arr = [] # declare an empty array\n arr[0] = \"kl\" # Err: index out of range\n arr = arr + [\"kl\"] # arr now is [\"kl\"]\n```\n\nYou can update a value in the array with the syntax above, as long as the array is greater than the index\nprovided, e.g:\n\n```python\narr = [\"this\", \"is\", \"ax\", \"array\", true, 1, 2.3]\narr[2] = \"an\" #fix the typo\nprint(arr[2]) # an\n\n```\n\nTo get the length of an array, you can use the built-in function `length`\n\n```python\n arr_len = length(arr) # 7\n\n```\n\nCharacters within a string can be accessed \u0026 updated just like an array:\n\n```python\n s = \"this is a strink\"\n s[2] # i\n length(s) # 16\n s[15] = \"g\" # fix the typo\n s # this is a string\n\n```\n\nHere are some other examples of what you can do with arrays:\n\n```python\ncount = 9\narr = null\n# arr = [1, [2, [3, [4, [5, [6, [7, [8, [9, null]]]]]]]]]\nwhile(count \u003e 0) {\n    arr = [count, arr]\n    count = count -1\n}\n# prints 1,2,3,4,5,6,7,8,9,done\nwhile(arr != null) {\n    print(arr[0] +\",\")\n    arr=arr[1]\n}\nprint(\"done\")\n\n```\n\n\u003chr\u003e\n\n### Functions\n\nThe function can be declared inline or as a block.\nIn the case of a function parameter, you either assign the function to a variable or\nuse an anonymous function block.\n\nParameters cannot be modified within a function. if you want to update something, you have to return it and reassign it.\n\n```python\n# no parameters\nhello = () =\u003e { println(\"hello, world!\") }\nhello()\n\n# one parameter\nhello_name = (name) =\u003e { println(\"hello \"+name) }\nhello_name(\"Bachir\")\n\n# takes an array and a function as a parameter\nfor_each = (arr, consumer) =\u003e {\n    count = 0\n    len = length(arr)\n    while(count \u003c len) {\n        consumer(arr[count])\n        count = count + 1\n    }\n    return \"\"  # do not print the count as the repl will print the latest statement\n}\n\nfor_each([\"Mohamed\", \"Hakim\", \"Sarah\", \"Yasmine\", \"Noah\", \"Sofia\", \"Sami\"], hello_name)\n# or for_each([\"Mohamed\", \"Hakim\", \"Sarah\", \"Yasmine\", \"Noah\", \"Sofia\", \"Sami\"],\n              (name) =\u003e { println(\"hello \"+name) }\n             )\n\n```\n\nParameters cannot be modified within a function. if you want to update something, you have to return it and reassign it.\nEverything that changes within the scope of a function won't have any effect on the outer scope.\n\nSome other examples of what you can do with functions:\n\n```python\narr  = [\"Mohamed\", \"Hakim\", \"Sarah\", \"Yasmine\", \"Noah\", \"Sofia\", \"Sami\"]\n\nacc  = (arr, v) =\u003e {arr + [v]} # arr is immutable, thus you have to reassign it if you call that function\n\narr = acc(arr, \"Malika\")\n\nfind_first = (arr, predicate) =\u003e {\n    len = length(arr)\n    count = 0\n    while(count \u003c len) {\n        temp = arr[count]\n        if(predicate(temp)) {\n            return temp\n        }\n        count = count + 1\n    }\n    return null\n}\n\n\nfind_first(arr, (v) =\u003e {\n    v[0] == \"S\" || v[0] == \"s\"\n})\n\n# recursive\nfact = (n) =\u003e {\n   if(n\u003e=1) {\n    n * fact(n-1)\n   }else {\n     1\n   }\n}\nfact(10)\n```\n\n\u003chr\u003e\n\n### Include a script file\n\nYou can dynamically load a script written in adana in the repl.\nAssuming you've cloned the repo and you use docker, here's an example of how to do it.\n\nNote that the extension must be `.adana`.\n\n- map the example directory as a docker volume:\n\n```\ndocker run -v $PWD/file_tests:/scripts -it adana\n```\n\n```python\n\ninclude(\"scripts/test_fn.adana\") # the built-in function to include\nm = map()\nm = push_v(\"nordine\", 34, m)\nget_v(\"nordine\", m)\n```\n\n\u003chr\u003e\n\n### Builtin functions\n\nThere are several built-in functions available.\n\nYou already have seen `length` to find the length of an array or string, `include` to include a script inside the repl and `println` to print something.\n\nHere is a list of built-in functions available:\n\n| name        | description                  | example                                          |\n| ----------- | ---------------------------- | ------------------------------------------------ |\n| floor       | floor double                 | `floor(4.7)`                                     |\n| ceil        | ceil double                  | `ceil(4.7)`                                      |\n| round       | round to places              | `round(4.46790, 3)`                              |\n| sqrt        | square root                  | `sqrt(2)`                                        |\n| abs         | absolute value               | `abs(-2)`                                        |\n| log         | logarithm                    | `log(2)`                                         |\n| ln          | natural logarithm            | `ln(2)`                                          |\n| length      | length of an array or string | `length(\"azert\")`                                |\n| sin         | sine of a number             | `sin(2)`                                         |\n| cos         | cosine of a number           | `cos(2)`                                         |\n| tan         | tangent of a number          | `tan(2.2)`                                       |\n| print       | print without a newline      | `print(\"hello\")`                                 |\n| println     | print with a newline         | `println(\"hello\")`                               |\n| include     | include a script             | `include(\"scripts/test_fn.adana\")`               |\n| require     | load a shared object         | `require(\"my_lib.so\")`                           |\n| to_int      | cast to int                  | `to_int(\"2\")`\u003cbr\u003e`to_int(2.2)`                   |\n| to_hex      | format num to hex            | `to_hex(2)`\u003cbr\u003e`to_hex(2.2)`                     |\n| to_binary   | format num to binary         | `to_binary(2)`                                   |\n| to_double   | cast to double               | `to_double(\"2.2\")`                               |\n| to_bool     | cast to bool                 | `to_bool(\"true\")`                                |\n| to_string   | cast to string               | `to_string(true)`                                |\n| drop        | drop a variable from context | `drop(\"myvar\")`\u003cbr\u003e`drop(arr[0])`                |\n| eval        | evaluate a string as code    | `eval(\"sqrt(9)\")`                                |\n| type_of     | type of variable             | `type_of(true)`                                  |\n| is_u8       | check if u8                  | `is_u8(0x1)`                                     |\n| is_i8       | check if i8                  | `is_i8(-1)`                                      |\n| is_int      | check if int                 | `is_int(512)`                                    |\n| is_double   | check if double              | `is_double(1.2)`                                 |\n| is_function | check if function            | `is_function(()=\u003e {1})`                          |\n| is_struct   | check if struct              | `is_struct(struct {})`                           |\n| is_bool     | check if bool                | `is_bool(false)`                                 |\n| is_array    | check if array               | `is_bool([1,2])`                                 |\n| is_error    | check if error               | `is_error(err)`                                  |\n| make_err    | create an error              | `make_err(\"oops\")`                               |\n| is_match    | check matching regex         | `is_match(\"AaAaAbbBBBb\", \"(?i)a+(?-i)b+\")`       |\n| capitalize  | capitalize str               | `capitalize(\"nordine\")`                          |\n| to_upper    | to Upper str                 | `to_upper(\"hello\")`                              |\n| to_lower    | to Lower str                 | `to_lower(\"HELLO\")`                              |\n| match       | match regex                  | `match(\"AaAaAbbBBBb\", \"(?i)a+(?-i)b+\")`          |\n| replace     | replace                      | `replace(\"AaAaAbbBBBb\", \"(?i)a+(?-i)b+\", \"xxx\")` |\n| replace_all | replace all                  | `replace_all(\"AaAaAbbBBBb\", \"A\", \"b\")`           |\n| jsonify     | jsonify value                | `jsonify(struct {a: 9})`                         |\n| parse_json  | parse a json string          | `parse_json(\"\"\"{\"a\": 9}\"\"\")`                     |\n\n#### Matching regexes\n\nThere are two built-in functions for matching a regex against a string:\n\n```python\npattern = \"\"\"(?i)a+(?-i)b+\"\"\"\ntext = \"AaAaAbbBBBb\"\nis_match(text, pattern) # true\n```\n\n```python\n# match [[\"Item1: $100\", \"Item1\", \"100\"], [\"Item2: $200\", \"Item2\", \"200\"], [\"Item3: $300\", \"Item3\", \"300\"]]\npattern = \"\"\"(\\w+): \\$(\\d+)\"\"\"\ntext = \"Item1: $100, Item2: $200, Item3: $300\"\nmatch(text, pattern)\n```\n\n\u003chr\u003e\n\nNote that you can use the repl command `script_ctx` to see what variables are stored in the context.\n\n## Namespaced aliases\n\nYou can alias useful commands in a separate namespace (e.g: \"work\", \"git\", \"docker\").\n\nYou can then run that command through the repl.\nThey will be save in disk so you can backup them, restore them etc.\n\nYou can also add any kind of values (e.g, ssh keys) to store them.\n\nThere is no possible interaction with the scripting language yet.\n\n### Try it\n\n`docker run -it -v $PWD/sample.json:/adanadb.json  nbittich/adana -im`\n\n`restore`\n\n`use misc`\n\n`ds`\n\n`printenv`\n\n### Available commands\n\n| name             | alt        | description                                                                                                                                                |\n| ---------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| put              | N/A        | Put a new value to current namespace. can have multiple aliases with option '-a'. e.g `put -a drc -a drcomp docker-compose`                                |\n| alias            | N/A        | Alias a key with another. e.g alias commit gc                                                                                                              |\n| describe         | ds         | List values within the current namespace.                                                                                                                  |\n| listns           | lsns       | List available namespaces.                                                                                                                                 |\n| currentns        | currentns  | Print current namespace.                                                                                                                                   |\n| backup           | bckp       | Backup the database of namespaces to the current directory                                                                                                 |\n| flush            | flush      | Force flush database                                                                                                                                       |\n| restore          | N/A        | Restore the database from current directory                                                                                                                |\n| deletens         | delns      | Delete namespace or clear current namespace values.                                                                                                        |\n| mergens          | merge      | Merge current with a given namespace                                                                                                                       |\n| delete           | del        | Remove value from namespace. e.g `del drc`                                                                                                                 |\n| get              |            | Get value from namespace. e.g `get drc`                                                                                                                    |\n| clip             | clippy     | Get value from namespace and copy it to clipboard. e.g `clip drc`                                                                                          |\n| exec             |            | Run a value from the namespace as an OS command. It is completely optional, if you just write the alias, it will also works e.g `exec drc` or simply `drc` |\n| cd               |            | Navigate to a directory in the filesystem                                                                                                                  |\n| use              |            | Switch to another namespace. default ns is DEFAULT. e.g `use linux`                                                                                        |\n| dump             |            | Dump namespace(s) as json. Take an optional parameter, the namespace name. e.g `dump linux`                                                                |\n| clear            | cls        | Clear the terminal.                                                                                                                                        |\n| print_script_ctx | script_ctx | Print script context                                                                                                                                       |\n| store_script_ctx |            | Store script context (optional name) e.g `store_script_ctx 12022023` or `store_script_ctx`                                                                 |\n| load_script_ctx  |            | Load script context (optional name) e.g `load_script_ctx 12022023` or `load_script_ctx`                                                                    |\n| ast              |            | print ast for script code e.g `ast 9*9`                                                                                                                    |\n| help             |            | Display help.                                                                                                                                              |\n\n### Shortcuts\n\n```\nCTRL + x =\u003e new line in the repl\nCTRL + d =\u003e quit\nCTRL + c =\u003e undo\nCTRL + l =\u003e clear screen\nCTRL + r =\u003e history search\nCTRL + p =\u003e π\n```\n\n### Environment variables\n\n```\nRUST_LOG=adana=debug adana\n```\n\n### Arguments\n\n#### TODO NOT EXHAUSTIVE\n\n#### Run a script without entering in the repl\n\n```\n# using file\nadana -sp /path/to/script.adana\n\n# using file with --daemon feature\nadana -sp /path/to/script.adana -d\n\n# using code\nadana -e 1+1\n```\n\n```\n# open an in memory db\n\nadana --inmemory\n\n```\n\n```\n# override db path \u0026 history path + no fallback in memory in case of an error (default to false)\n# path must exist! file doesn't have to.\n\nadana --dbpath /tmp/mydb.db --historypath /tmp/myhistory.txt --nofb\n\n```\n\n```\n# specify shared lib path\nadana -slp /tmp/shared\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbittich%2Fadana","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnbittich%2Fadana","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbittich%2Fadana/lists"}