Sha256: 57853bd95d65d4ac372655fb0807a078c5d0a66d4004c5bb5e64e645d32ca7f9

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8

require "thor"

require_relative 'doi_utils'
require_relative 'utils'

module Bolognese
  class CLI < Thor
    include Bolognese::DoiUtils
    include Bolognese::Utils

    def self.exit_on_failure?
      true
    end

    # from http://stackoverflow.com/questions/22809972/adding-a-version-option-to-a-ruby-thor-cli
    map %w[--version -v] => :__print_version

    desc "--version, -v", "print the version"
    def __print_version
      puts Bolognese::VERSION
    end

    desc "", "convert metadata"
    method_option :from, aliases: "-f"
    method_option :to, aliases: "-t", default: "schema_org"
    method_option :regenerate, :type => :boolean, :force => false
    def convert(input)
      id = normalize_id(input)

      if id.present?
        from = options[:from] || find_from_format(id: id)
      else
        ext = File.extname(input)
        if %w(.bib .ris .xml .json).include?(ext)
          string = IO.read(input)
        else
          $stderr.puts "File type #{ext} not supported"
          exit 1
        end
        from = options[:from] || find_from_format(string: string, ext: ext)
      end

      to = options[:to] || "schema_org"

      write(id: id, string: string, from: from, to: to, regenerate: options[:regenerate])
    end

    default_task :convert
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bolognese-0.9.8 lib/bolognese/cli.rb
bolognese-0.9.7 lib/bolognese/cli.rb
bolognese-0.9.6 lib/bolognese/cli.rb
bolognese-0.9.5 lib/bolognese/cli.rb
bolognese-0.9.4 lib/bolognese/cli.rb
bolognese-0.9.3 lib/bolognese/cli.rb
bolognese-0.9.2 lib/bolognese/cli.rb
bolognese-0.9.1 lib/bolognese/cli.rb