Commit 46ee3d54 authored by Jonathan Riddell's avatar Jonathan Riddell 🛶

more options

parent 10967cd2
......@@ -23,16 +23,31 @@
require 'optparse'
require_relative 'lib/appstream-metainfo-release-update'
@date = "today"
@release_to_show = 0
parser = OptionParser.new do |opts|
opts.banner = <<-EOS
Usage: appstream-metainfo-release-update 'org.foo.metainfo.xml'
EOS
opts.on("-v", "--version VERSION",
"version to add") do |vers|
@version << vers
end
opts.on("-d", "--datestring DATE_STRING",
"date to use 'today' 'next Thursday' etc") do |date_string|
@date << date_string
end
opts.on("-r", "--releases_to_show RELEASES_TO_SHOW",
"how many releases to include in file") do |releases_to_show|
@releases_to_show = releases_to_show || 0
end
end
parser.parse!
abort parser.help if ARGV.empty?
file_name = ARGV[0]
updater = MetaInfoUpdater.new(file_name)
updater = MetaInfoUpdater.new(file_name, @version, @date, @releases_to_show)
updater.open_file
updater.save_file
......@@ -27,15 +27,19 @@ class MetaInfoUpdater
attr_accessor :filename
attr_accessor :doc
attr_accessor :testing
attr_accessor :version
attr_accessor :date_string
attr_accessor :releases_to_show
def initialize(filename, testing = false)
def initialize(filename, version, date_string="today", releases_to_show=0)
@filename = filename
@testing = testing
@version = version
@date_string = date_string
@releases_to_show = releases_to_show
end
def open_file
puts "Filename #{@filename}"
# TODO check file exists etc
abort "No such file" if not File.exists?(@filename)
@doc = File.open(@filename) { |f| Nokogiri::XML(f, &:noblanks) }
component = @doc.at_css("component")
releases = component.add_child("<releases><release version='1.0' date='today'/></releases>")
......
require 'minitest/autorun'
require_relative '../lib/appstream-metainfo-release-update'
class MetaInfoUpdaterTest < MiniTest::Unit::TestCase
class MetaInfoUpdaterTest < MiniTest::Test
def test_new_release
updater = MetaInfoUpdater.new("data/no-releases.appdata.xml", true)
updater = MetaInfoUpdater.new("data/no-releases.appdata.xml", "1.0")
updater.testing = true
updater.open_file
updater.save_file
# open the __FILE__
# do the thing
# compare the file
assert_equal(File.read("data/no-releases.appdata.xml.testout"), File.read("data/no-releases.appdata.xml.good"))
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment