From 222cac5b0d7566c272f0911669884e6ca32c9f11 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 7 Feb 2020 15:49:37 +0100 Subject: [PATCH] Improve documentation on 'allowFun' parameters --- README.md | 10 +++++----- docparse/src/main.rs | 24 ++++++++++-------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7976d23..f182596 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,13 @@ it is converted to an attribute set equivalent to `{ root = theArg; }`. | `version` | The version of the derivation. | | `src` | Used by `naersk` as source input to the derivation. When `root` is not set, `src` is also used to discover the `Cargo.toml` and `Cargo.lock`. | | `root` | Used by `naersk` to read the `Cargo.toml` and `Cargo.lock` files. May be different from `src`. When `src` is not set, `root` is (indirectly) used as `src`. | -| `cargoBuild` | The command to use for the build. Default: `''cargo $cargo_options build $cargo_build_options''` | -| `cargoBuildOptions` | Options passed to cargo build, i.e. `cargo build `. These options can be accessed during the build through the environment variable `cargo_build_options`.
Note: naersk relies on the `--out-dir out` option.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' "--out-dir" "out" ]` | +| `cargoBuild` | The command to use for the build. When set to a function, the function is applied to the default value.
Default: `''cargo $cargo_options build $cargo_build_options''` | +| `cargoBuildOptions` | Options passed to cargo build, i.e. `cargo build `. These options can be accessed during the build through the environment variable `cargo_build_options`.
Note: naersk relies on the `--out-dir out` option.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
When set to a function, the function is applied to the default value.
Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' "--out-dir" "out" ]` | | `doCheck` | When true, `checkPhase` is run. Default: `true` | -| `cargoTestCommands` | The commands to run in the `checkPhase`. Default: `[ ''cargo $cargo_options test $cargo_test_options'' ]` | -| `cargoTestOptions` | Options passed to cargo test, i.e. `cargo test `. These options can be accessed during the build through the environment variable `cargo_test_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ]` | +| `cargoTestCommands` | The commands to run in the `checkPhase`. When set to a function, the function is applied to the default value.
Default: `[ ''cargo $cargo_options test $cargo_test_options'' ]` | +| `cargoTestOptions` | Options passed to cargo test, i.e. `cargo test `. These options can be accessed during the build through the environment variable `cargo_test_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
When set to a function, the function is applied to the default value.
Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ]` | | `buildInputs` | Extra `buildInputs` to all derivations. Default: `[]` | -| `cargoOptions` | Options passed to all cargo commands, i.e. `cargo ...`. These options can be accessed during the build through the environment variable `cargo_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
Default: `[ "-Z" "unstable-options" ]` | +| `cargoOptions` | Options passed to all cargo commands, i.e. `cargo ...`. These options can be accessed during the build through the environment variable `cargo_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
When set to a function, the function is applied to the default value.
Default: `[ "-Z" "unstable-options" ]` | | `doDoc` | When true, `cargo doc` is run and a new output `doc` is generated. Default: `false` | | `release` | When true, all cargo builds are run with `--release`. The environment variable `cargo_release` is set to `--release` iff this option is set. Default: `true` | | `override` | An override for all derivations involved in the build. Default: `(x: x)` | diff --git a/docparse/src/main.rs b/docparse/src/main.rs index 7e78aca..854c096 100644 --- a/docparse/src/main.rs +++ b/docparse/src/main.rs @@ -43,11 +43,10 @@ fn print_mk_attrs(mk_attrs: SyntaxNode) { for e in body.entries() { let k = e.key().expect("No key").path().next().unwrap(); let v = e.value(); - let mshown = if let Some(x) = v.clone().and_then(OrDefault::cast) { + let mextra_note = if let Some(x) = v.clone().and_then(OrDefault::cast) { x.default().and_then(|def| { - let shown = format!("{}", def); - if shown != "null" { - Some(shown) + if def.to_string() != "null" { + Some(format!("Default: `{}`", def)) } else { None } @@ -63,12 +62,10 @@ fn print_mk_attrs(mk_attrs: SyntaxNode) { .lambda() .expect("No inner lambda"); if inner2.to_string() == "allowFun" { - Some(format!("{}", x.value().unwrap())) + Some(format!("When set to a function, the function is applied to the default value.
Default: `{}`", x.value().unwrap())) } else { None } - } else if let Some(x) = v.clone().and_then(Lambda::cast) { - Some("lambda".to_string()) } else { None }; @@ -79,14 +76,13 @@ fn print_mk_attrs(mk_attrs: SyntaxNode) { lines.push(l); } - let sss; - if let Some(shown) = mshown { - lines.push("Default:"); - sss = format!("`{}`", shown); - lines.push(&sss); - } let descr = lines.join(" "); - println!("| `{}` | {} |", k, descr); + if let Some(extra_note) = mextra_note { + println!("| `{}` | {} {} |", k, descr, extra_note); + lines.push(extra_note.clone().as_ref()); + } else { + println!("| `{}` | {} |", k, descr); + } } }