Sha256: 7a9bae9c1e8a6cae85ff744446410140e7fb2e38c44485f0d984b657590740e0

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require "firestore"
require "tools/modinfo"

module Icarus
  module Mod
    module CLI
      # Sync CLI command definitions
      class Add < SubcommandBase
        desc "modinfo", "Adds an entry to 'meta/modinfo/list'"
        def modinfo(item)
          firestore = Firestore.new
          payload = [firestore.list(:modinfo), item].flatten.compact

          puts firestore.update(:modinfo, payload, merge: true) ? "Success" : "Failure"
        end

        desc "toolinfo", "Adds an entry to 'meta/toolinfo/list'"
        def toolinfo(item)
          firestore = Firestore.new
          payload = [firestore.list(:toolinfo), item].flatten.compact

          puts firestore.update(:toolinfo, payload, merge: true) ? "Success" : "Failure"
        end

        desc "repos", "Adds an entry to 'meta/repos/list'"
        def repos(item)
          firestore = Firestore.new
          payload = [firestore.list(:repositories), item].flatten.compact

          puts firestore.update(:repositories, payload, merge: true) ? "Success" : "Failure"
        end

        desc "mod", "Adds an entry to 'mods'"
        method_option :modinfo, type: :string, required: true, default: "modinfo.json", desc: "Path to the modinfo.json file"
        def mod
          firestore = Firestore.new
          data = options[:modinfo]

          if data.nil? || !File.exist?(data)
            warn "Invalid data file: #{data}"
            exit 1
          end

          JSON.parse(File.read(data), symbolize_names: true)[:mods].each do |mod|
            modinfo = Icarus::Mod::Tools::Modinfo.new(mod)

            unless modinfo.valid?
              warn "Invalid modinfo: #{modinfo.errors}"
              exit 1
            end

            puts firestore.update(:mod, modinfo, merge: true) ? "Success" : "Failure"
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Icarus-Mod-Tools-2.0 lib/icarus/mod/cli/add.rb