get_hg_hash 527 B

12345678910111213141516171819202122
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Path::Tiny;
  4. use JSON;
  5. sub exit_error {
  6. print STDERR "Error: ", $_[0], "\n";
  7. exit (exists $_[1] ? $_[1] : 1);
  8. }
  9. exit_error("Wrong number of arguments", 1) unless @ARGV == 2;
  10. my ($file, $locale) = @ARGV;
  11. my $json_text = path($file)->slurp_raw;
  12. exit_error("Error reading $file", 2) unless defined $json_text;
  13. my $data = decode_json($json_text);
  14. my $changeset = $data->{$locale}{revision};
  15. exit_error("Can't find locale $locale in $file", 3) unless $changeset;
  16. print "$changeset\n";