Sha256: 8c74bcdc2bca4132e4e854711859e666d86e5130ea46a2b49731f4a185429f8a

Contents?: true

Size: 1.39 KB

Versions: 75

Compression:

Stored size: 1.39 KB

Contents

#!/usr/bin/env ruby

require_relative '../lib/format_parser'
require 'json'
require 'optparse'

options = {results: :first}
OptionParser.new do |opts|
  opts.banner = 'Usage: format_parser_inspect --all my_file.jpg my_other_file.png'
  opts.on('-a', '--all', 'Return all results instead of just the first one') do |_v|
    options[:results] = :all
  end
  opts.on('--natures[=NATURES]', 'Only scan specific natures (comma-separated: image, audio)', Array) do |v|
    options[:natures] = v.map { |e| e.strip.downcase.to_sym }
  end
  opts.on('--formats[=FORMATS]', 'Only scan specific formats (comma-separated: jpg, tif)', Array) do |v|
    options[:formats] = v.map { |e| e.strip.downcase.to_sym }
  end
end.parse!

did_detect = false
return_values = ARGV.map do |path_or_url|
  method_name = path_or_url =~ /^http(s?)\:\/\// ? :parse_http : :parse_file_at
  result_or_results = FormatParser.public_send(method_name, path_or_url, **options)
  if options[:results] != :first
    did_detect = true if result_or_results.any?
    {
      source_path_or_url: path_or_url,
      options: options,
      ambiguous: result_or_results.length > 1,
      results: result_or_results,
    }
  else
    did_detect = true if result_or_results
    {
      source_path_or_url: path_or_url,
      options: options,
      result: result_or_results,
    }
  end
end

puts JSON.pretty_generate(return_values)
did_detect ? exit(0) : exit(1)

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
format_parser-0.25.2 exe/format_parser_inspect
format_parser-0.25.1 exe/format_parser_inspect
format_parser-0.25.0 exe/format_parser_inspect
format_parser-0.24.2 exe/format_parser_inspect
format_parser-0.24.1 exe/format_parser_inspect
format_parser-0.24.0 exe/format_parser_inspect
format_parser-0.23.1 exe/format_parser_inspect
format_parser-0.23.0 exe/format_parser_inspect
format_parser-0.22.1 exe/format_parser_inspect
format_parser-0.22.0 exe/format_parser_inspect
format_parser-0.21.1 exe/format_parser_inspect
format_parser-0.21.0 exe/format_parser_inspect
format_parser-0.20.1 exe/format_parser_inspect
format_parser-0.20.0 exe/format_parser_inspect
format_parser-0.19.0 exe/format_parser_inspect
format_parser-0.18.0 exe/format_parser_inspect
format_parser-0.17.0 exe/format_parser_inspect
format_parser-0.16.1 exe/format_parser_inspect
format_parser-0.16.0 exe/format_parser_inspect
format_parser-0.15.1 exe/format_parser_inspect