chiark / gitweb /
docs: Document new substitution syntax
[otter.git] / update-cargo-metadata
1 #!/bin/bash
2 # usage:
3 #    ./update-cargo-metadata
4 # copies from toplevel Cargo.toml to others
5 # the part copied is the paragraph which starts with version=
6
7 set -e
8
9 fail () { echo >&2 "${0##*/}: error: $*"; exit 12; }
10
11 [ $# = 0 ] || fail "bad usage"
12
13 files=$(git ls-files :\*/Cargo.toml :Cargo.toml)
14
15 for f in $files; do
16     perl -i~ -pe '
17         BEGIN {
18             $/ = "\n\n";
19             open I, "Cargo.toml" or die $!;
20             our $re = qr{^version\s*\=};
21             our $std;
22             while (<I>) {
23                 next unless m{$re};
24                 $std = $_;
25                 last;
26             }
27             die "not found in ./Cargo.toml" unless defined $std;
28 #           $std =~ s{\s*$}{};
29         }
30
31         next unless m{$re};
32         next if $y++;
33 #       s{\s*$}{};;
34 #       $_ = $std.$&;
35         $_ = $std;
36         END {
37             $y or die "not found in '$f'";
38         }
39     ' $f
40 done
41
42 echo "working tree file(s) maybe updated, check with git."