Sha256: e80b6b28653c48d9c3b67e6c739a3574fbeb6813b0b812ccf6a6b4cf9e927bd9

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'masking/config'
require 'masking/version'
require 'masking/errors'
require 'masking/cli/error_message'
require 'optparse'

module Masking
  class Cli
    def initialize(argv)
      @argv = argv
    end

    def run
      option_parser.parse(argv)
      Masking.run
    rescue Masking::Error => e
      warn(Masking::Cli::ErrorMessage.new(e).message(config_file_path: Masking.config.target_columns_file_path))
      exit(false)
    end

    private

    attr_reader :argv

    def option_parser
      OptionParser.new do |parser|
        parser.banner = 'Usage: masking [options]'

        define_config_option(parser)
        define_version_option(parser)
      end
    end

    def define_config_option(parser)
      parser.on('-cFILE_PATH', '--config=FILE_PATH', 'specify config file. default: masking.yml') do |file_path|
        Masking.configure do |config|
          config.target_columns_file_path = file_path
        end
      end
    end

    def define_version_option(parser)
      parser.on('-v', '--version', 'version') do
        puts Masking::VERSION
        exit(true)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
masking-1.1.2 lib/masking/cli.rb
masking-1.1.2.pre.alpha lib/masking/cli.rb
masking-1.1.1 lib/masking/cli.rb
masking-1.1.0 lib/masking/cli.rb
masking-1.0.1 lib/masking/cli.rb