appstream-metainfo-release-update 2.01 KB
Newer Older
Jonathan Riddell's avatar
Jonathan Riddell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env ruby
# coding: utf-8
# frozen_string_literal: true

# Copyright (C) 2019 Jonathan Riddell <sitter@kde.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) version 3, or any
# later version accepted by the membership of KDE e.V. (or its
# successor approved by the membership of KDE e.V.), which shall
# act as a proxy defined in Section 6 of version 3 of the license.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library.  If not, see <http://www.gnu.org/licenses/>.

require 'optparse'
24
require_relative 'lib/appstream-metainfo-release-update'
Jonathan Riddell's avatar
Jonathan Riddell committed
25

Jonathan Riddell's avatar
Jonathan Riddell committed
26
@date = "today"
Jonathan Riddell's avatar
Jonathan Riddell committed
27
@releases_to_show = 0
Jonathan Riddell's avatar
Jonathan Riddell committed
28
@dateoff = false # double negative but I can't work out a nicer way
Jonathan Riddell's avatar
Jonathan Riddell committed
29

Jonathan Riddell's avatar
Jonathan Riddell committed
30 31
parser = OptionParser.new do |opts|
  opts.banner = <<-EOS
Jonathan Riddell's avatar
Jonathan Riddell committed
32
Usage: appstream-metainfo-release-update 'org.foo.metainfo.xml'
Jonathan Riddell's avatar
Jonathan Riddell committed
33
  EOS
Jonathan Riddell's avatar
Jonathan Riddell committed
34
  opts.on("-v", "--version VERSION",
Jonathan Riddell's avatar
Jonathan Riddell committed
35
          "version to add e.g. 1.0") do |vers|
Jonathan Riddell's avatar
Jonathan Riddell committed
36
    @version = vers
Jonathan Riddell's avatar
Jonathan Riddell committed
37 38
  end
  opts.on("-d", "--datestring DATE_STRING",
Jonathan Riddell's avatar
Jonathan Riddell committed
39
          "date to use 'today' 'next Thursday' '2018-01-01' etc") do |date_string|
Jonathan Riddell's avatar
Jonathan Riddell committed
40
    @date = date_string || "today"
Jonathan Riddell's avatar
Jonathan Riddell committed
41
  end
42
  opts.on("-o", "--dateoff",
Jonathan Riddell's avatar
Jonathan Riddell committed
43 44 45
          "do not include a date") do |date_off|
    @dateoff = date_off
  end
Jonathan Riddell's avatar
Jonathan Riddell committed
46
  opts.on("-r", "--releases_to_show RELEASES_TO_SHOW",
Jonathan Riddell's avatar
Jonathan Riddell committed
47
          "how many releases to include in file (default infinite)") do |releases_to_show|
Jonathan Riddell's avatar
Jonathan Riddell committed
48
    @releases_to_show = releases_to_show.to_i || 0
Jonathan Riddell's avatar
Jonathan Riddell committed
49
  end
Jonathan Riddell's avatar
Jonathan Riddell committed
50 51 52 53 54 55
end
parser.parse!

abort parser.help if ARGV.empty?
file_name = ARGV[0]

Jonathan Riddell's avatar
Jonathan Riddell committed
56
updater = MetaInfoUpdater.new(file_name, @version, @date, @dateoff, @releases_to_show)
Jonathan Riddell's avatar
Jonathan Riddell committed
57
updater.open_file
58
updater.save_file