Sha256: aa01e3b8342d7e70db486b93fa33b78d959fa6cef7d28bfd1cf8d4091d893c04

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "colorize"

module Mihari
  module Commands
    module Initialization
      def self.included(thor)
        include Mixins::Configuration
        include Mixins::Rule

        thor.class_eval do
          desc "config", "Create a config file"
          method_option :filename, type: :string, default: "mihari.yml"
          def config
            filename = options["filename"]

            warning = "#{filename} exists. Do you want to overwrite it? (y/n)"
            if File.exist?(filename) && !(yes? warning)
              return
            end

            initialize_config_yaml filename

            puts "The config file is initialized as #{filename}.".colorize(:blue)
          end

          desc "rule", "Create a rule file"
          method_option :filename, type: :string, default: "rule.yml"
          def rule
            filename = options["filename"]

            warning = "#{filename} exists. Do you want to overwrite it? (y/n)"
            if File.exist?(filename) && !(yes? warning)
              return
            end

            initialize_rule_yaml filename

            puts "The rule file is created as #{filename}.".colorize(:blue)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mihari-3.4.0 lib/mihari/commands/init.rb
mihari-3.3.0 lib/mihari/commands/init.rb
mihari-3.2.0 lib/mihari/commands/init.rb
mihari-3.1.0 lib/mihari/commands/init.rb
mihari-3.0.1 lib/mihari/commands/init.rb
mihari-3.0.0 lib/mihari/commands/init.rb