Sha256: 2c397156bcbe0f8cd7754b3ffe97c663a9e8be870c7b4dcb59de45aa6260b69e

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "colorize"

module Mihari
  module Commands
    module Initialization
      include Mixins::Configuration
      include Mixins::Rule

      def self.included(thor)
        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 initialized as #{filename}.".colorize(:blue)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mihari-3.12.0 lib/mihari/commands/init.rb
mihari-3.11.0 lib/mihari/commands/init.rb
mihari-3.10.1 lib/mihari/commands/init.rb
mihari-3.10.0 lib/mihari/commands/init.rb
mihari-3.9.2 lib/mihari/commands/init.rb
mihari-3.9.1 lib/mihari/commands/init.rb
mihari-3.9.0 lib/mihari/commands/init.rb
mihari-3.8.1 lib/mihari/commands/init.rb
mihari-3.8.0 lib/mihari/commands/init.rb
mihari-3.7.2 lib/mihari/commands/init.rb
mihari-3.7.1 lib/mihari/commands/init.rb
mihari-3.7.0 lib/mihari/commands/init.rb
mihari-3.6.1 lib/mihari/commands/init.rb
mihari-3.6.0 lib/mihari/commands/init.rb
mihari-3.5.0 lib/mihari/commands/init.rb