Sha256: 47ee4c1b152363548376ead5a9a6ea0dd8fcfe6da3b22723508a1aac80696f1c
Contents?: true
Size: 1.34 KB
Versions: 5
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module Mihari module Commands module JSON def self.included(thor) thor.class_eval do desc "import_from_json", "Give a JSON input via STDIN" def import_from_json(input = nil) with_error_handling do json = input || $stdin.gets.chomp raise ArgumentError, "Input not found: please give an input in a JSON format" unless json json = parse_as_json(json) raise ArgumentError, "Invalid input format: an input JSON data should have title, description and artifacts key" unless valid_json?(json) title = json["title"] description = json["description"] artifacts = json["artifacts"] tags = json["tags"] || [] basic = Analyzers::Basic.new(title: title, description: description, artifacts: artifacts, source: "json", tags: tags) basic.ignore_old_artifacts = options["ignore_old_artifacts"] || false basic.ignore_threshold = options["ignore_threshold"] || 0 basic.run end end no_commands do def parse_as_json(input) ::JSON.parse input rescue ::JSON::ParserError => _e nil end end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems