1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-11 11:47:03 +03:00

Update commands and examples from README (#1743)

This commit is contained in:
Yann Hamdaoui 2023-12-20 09:31:07 +00:00 committed by GitHub
parent 4e3a030b5b
commit 09035ca620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,35 +116,38 @@ the `nickel-lang-core` crate documentation).
2. Run your first program: 2. Run your first program:
```console ```console
$ nickel <<< 'let x = 2 in x + x' $ nickel eval <<< '["hello", "world"] |> std.string.join ", "'
4 "hello, world"
``` ```
Or load it from a file: Or load it from a file:
```console ```console
$ echo 'let s = "world" in "Hello, " ++ s' > program.ncl $ echo 'let s = "world" in "hello, %{s}"' > program.ncl
$ nickel -f program.ncl $ nickel eval program.ncl
"Hello, world" "hello, world"
``` ```
3. Start a REPL: 3. Start a REPL:
```console ```console
$ nickel repl $ nickel repl
nickel> let x = 2 in x + x nickel> {"hello" = true, "world" = true, "universe" = false}
4 |> std.record.to_array
|> std.array.filter (fun {field, value} => value)
|> std.array.map (fun {field, value} => field)
|> std.string.join ", "
nickel> "hello, world"
``` ```
Use `:help` for a list of available commands. Use `:help` for a list of available commands.
4. Export your configuration to JSON, YAML or TOML: 4. Export your configuration to JSON, YAML or TOML:
```console ```console
$ nickel export --format json <<< '{foo = "Hello, world!"}' $ nickel export --format json <<< '{content = "hello, world"}'
{ {
"foo": "Hello, world!" "content": "hello, world"
} }
``` ```
@ -171,11 +174,10 @@ enabled when installing nickel with `cargo install` as of Nickel version 1.3.0.
In this case, please use [Topiary](https://github.com/tweag/topiary/) separately In this case, please use [Topiary](https://github.com/tweag/topiary/) separately
to format Nickel source code. to format Nickel source code.
To format a Nickel source file, use `nickel format` (`-i` is short for To format one or several Nickel source files, use `nickel format`:
`--in-place`):
```console ```console
nickel format -i -f my-config.ncl nickel format network.ncl container.ncl api.ncl
``` ```
Nickel uses [Topiary](https://github.com/tweag/topiary/) to format Nickel code Nickel uses [Topiary](https://github.com/tweag/topiary/) to format Nickel code
@ -195,8 +197,8 @@ code editor.
- **With Nix**: If you have [Nix](https://nixos.org/nix) installed: - **With Nix**: If you have [Nix](https://nixos.org/nix) installed:
```console ```console
nix-shell nix-shell # if you don't use Nix flakes
nix develop # if you use Nix Flakes nix develop # if you use Nix flakes
``` ```
You will be dropped in a shell, ready to build. You can use You will be dropped in a shell, ready to build. You can use
@ -208,11 +210,18 @@ code editor.
1. Build Nickel: 1. Build Nickel:
```console ```console
cargo build --release cargo build -p nickel-lang-cli --release
``` ```
And voilà! Generated files are placed in `target/release`. And voilà! Generated files are placed in `target/release`.
You can directly build and run the Nickel binary and pass argument after `--`
by using `cargo run`:
```console
cargo run --bin nickel -- eval foo.ncl
```
### Test ### Test
Run tests with Run tests with
@ -243,8 +252,9 @@ You can find examples in the [`./examples`](./examples) directory.
## Current state and roadmap ## Current state and roadmap
Nickel is currently released in version `1.0`. We expect the core design of the Nickel is currently released in version `1.3`. We expect the core design of the
language to be stable and the language to be useful for real-world applications. language to be stable and the language to be useful for real-world applications.
The next steps we plan to work on are: The next steps we plan to work on are:
- Nix integration: being able to seamlessly use Nickel to write packages and - Nix integration: being able to seamlessly use Nickel to write packages and