Sha256: e59ce17a4aa38e63c4156d915cdac999bbc74acc433bdfac61f53dac3a5b415c

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'mixlib/cli'
require 'spanx/helper/exit'

module Spanx
  class CLI
    include Mixlib::CLI
    include Spanx::Helper::Exit
    include Spanx::Helper::Subclassing

    attr_reader :args

    # the first element of ARGV should be a subcommand, which maps to
    # a class in spanx/cli/
    def run(args = ARGV)
      @args = args
      validate!
      Spanx::CLI.subclass_class(args.shift).new.run(args)
    end

    private

    def validate!
      error_exit_with_msg("No command given") if args.empty?
      @command = args.first
      error_exit_with_msg("No command found matching #{@command}") unless Spanx::CLI.subclasses.include?(@command)
    end

    def generate_config(argv)
      parse_options argv
      config.merge! Spanx::Config.new(config[:config_file])
      parse_options argv

      if config[:debug]
        STDOUT.sync = true
      end

      Spanx::Logger.enable if config[:debug]
    end

  end
end

require 'spanx/cli/watch'
require 'spanx/cli/analyze'
require 'spanx/cli/disable'
require 'spanx/cli/enable'
require 'spanx/cli/flush'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spanx-0.1.1 lib/spanx/cli.rb
spanx-0.1.0 lib/spanx/cli.rb