-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexamples.sh
executable file
·76 lines (70 loc) · 2.92 KB
/
examples.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# shellcheck disable=SC1003 disable=SC2016
quote_args() {
for arg in "$@"; do
printf '%s ' "$( [[ $arg =~ ^[a-zA-Z0-9_\.-]+$ ]] <<< "$arg" && printf '%s' "$arg" || printf '%s' "'${arg//'/\\'}'" )"
done
}
quote_asciidoc() {
for arg in "$@"; do
printf '%s ' "$( [[ $arg =~ ^[a-zA-Z0-9_\.-]+$ ]] && {
[[ $arg == -* ]] && printf '*%s*' "$arg" || printf '%s' "$arg"
} || printf '%s' "\\'${arg//'/\\'}'" )"
done
}
run-example() {
title=$1; shift
shift # nix-prefetch
printf '%s\n' " *nix-prefetch* $(quote_asciidoc "$@")" >> /dev/fd/3
printf '\n%s\n' "${title}:
"'```'"
$ nix-prefetch $(quote_args "$@")
$(nix-prefetch "$@" 2>&1)
"'```' >> /dev/fd/4
}
{
run-example 'A package source' \
nix-prefetch hello.src
run-example 'A package without a hash defined' \
nix-prefetch '{ stdenv, fetchurl }: stdenv.mkDerivation rec {
name = "test";
src = fetchurl { url = http://ftpmirror.gnu.org/hello/hello-2.10.tar.gz; };
}'
run-example 'A package checked to already be in the Nix store thats not installed' \
nix-prefetch hello --check-store --verbose
run-example 'A package checked to already be in the Nix store thats installed (i.e. certain the hash is valid, no need to redownload)' \
nix-prefetch git --check-store --verbose
run-example 'Passing a list rather than a string argument' \
nix-prefetch fetchurl --urls --expr '[ mirror://gnu/hello/hello-2.10.tar.gz ]'
run-example 'Passing an argument to the expression' \
nix-prefetch '{ name }: pkgs.${name}' --argstr name fetchurl --url mirror://gnu/hello/hello-2.10.tar.gz
run-example 'Modify the Git revision of a call to `fetchFromGitHub`'\
nix-prefetch openraPackages.engines.bleed --fetchurl --rev master
run-example 'Hash validation' \
nix-prefetch hello 0000000000000000000000000000000000000000000000000000
run-example 'A specific file fetcher' \
nix-prefetch hello_rs.cargoDeps --fetcher '<nixpkgs/pkgs/build-support/rust/fetchCargoTarball.nix>'
run-example 'List all known fetchers in Nixpkgs' \
nix-prefetch --list --deep
run-example 'Get a specialized help message for a fetcher' \
nix-prefetch fetchFromGitHub --help
run-example 'A package for i686-linux' \
nix-prefetch '(import <nixpkgs> { system = "i686-linux"; }).scilab-bin'
printf -v examples '\n[subs="verbatim,quotes"]\n%s\n' "$(< /dev/fd/3)"
examples=${examples//\\/\\\\}
printf '%s\n' "$(awk -v "examples=$examples" '
$0 == "== Examples" { skip=1; print; print examples; next }
skip && $1 == "==" { skip=0 }
!skip { print }
' doc/nix-prefetch.1.asciidoc)" > doc/nix-prefetch.1.asciidoc
examples=$(< /dev/fd/4)
examples=${examples//\\/\\\\}
printf '%s\n' "$(awk -v "examples=$examples" '
$0 == "Examples" { skip=1; print; next }
skip && $0 == "---" { print; print examples; exit }
skip { skip=0 }
{ print }
' README.md)" > README.md
} 3<<EOF 4<<EOF
EOF
EOF