vasyl-purchel/alpaca

View on GitHub
bin/alpaca

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'gli'
require 'alpacabuildtool'

module AlpacaBuildTool
  ##
  # The *GliWrapper* module provides command line interface by using GLI::App
  module GliWrapper
    include GLI::App
    extend self

    program_desc 'is a build tool for Visual Studio solutions'
    subcommand_option_handling :normal
    arguments :strict
    gem_path = File.join(File.expand_path(File.dirname(__FILE__)), '..')
    version Versioning.parse(File.join(gem_path, '.semver')).to_s

    on_error do |exception|
      puts exception.backtrace if ENV['DEV'] == 'true'
      true
    end

    desc 'Solutions search pattern'
    default_value '**/*.sln'
    flag [:p, :pattern]

    desc 'Compile solution[s]'
    long_desc 'Compiling each solution founded from pattern in global options'
    command :compile do |command|
      command.desc 'Build solution in Debug mode'
      command.switch :d, :debug

      command.desc 'Update project versions'
      command.switch :u, :update

      command.action do |global, options, _|
        Application.new.compile(global[:p],
                                debug: options[:d] || false,
                                update_version: options[:u] || false)
      end
    end

    desc 'Test solution[s]'
    long_desc 'Testing each solution founded from pattern in global options'
    command :test do |command|
      command.desc 'Test solution in Debug mode'
      command.switch :d, :debug, negatable: false

      command.desc 'Run tests with coverage'
      command.switch [:c, :coverage]

      command.desc 'Test type'
      command.default_value 'all'
      command.flag :t, :type

      command.action do |global, options, _|
        Application.new.test(global[:p],
                             debug: options[:d] || false,
                             coverage: options[:c] || false,
                             type: options[:t])
      end
    end

    desc 'Generate reports for solution[s]'
    long_desc 'Generate reports for all founded results for solutions'
    command :report do |command|
      command.desc 'Report category'
      command.default_value 'all'
      command.flag :t, :type

      command.action do |global, options, _|
        Application.new.report(global[:p], type: options[:t])
      end
    end

    desc 'Create packages for solution[s]'
    long_desc 'Create new packages for solutions'
    command :pack do |command|
      command.desc 'Pack package in Debug mode'
      command.switch :d, :debug, negatable: false, default_value: false

      command.desc 'Push package after it created if it contains changes'
      command.switch :p, :push, default_value: false

      command.desc 'Force push package after it created'
      command.switch :f, :force, default_value: false

      command.action do |global, options, _|
        Application.new.package(global[:p], options)
      end
    end

    desc 'Release packages for solution[s]'
    long_desc 'Update package to release version and push it'
    command :release do |command|
      command.desc 'Push to the source after released'
      command.switch :p, :push, default_value: true

      command.desc 'Force push package after it created'
      command.switch :f, :force, default_value: false

      command.action do |global, options, _|
        Application.new.release(global[:p], options)
      end
    end

    desc 'Update solution[s] versions'
    long_desc 'Update version for each solution'
    command :update do |command|
      command.desc 'Version dimension to be updated(patch, minor..)'
      command.default_value 'patch'
      command.flag :d, :dimension

      command.action do |global, options, _|
        Application.new.update(global[:p], options)
      end
    end

    desc 'Configure alpaca to your needs'
    long_desc 'Save configuration into local/global conf files
      for further usage'
    command :configure do |command|
      command.desc 'configure solution[s] from global pattern'
      command.arg_name 'node1.node2.property=value', :multiple
      command.command :local do |subcommand|
        subcommand.action do |global, _, arguments|
          Application.new.configure_local(global[:p], arguments)
        end
      end

      command.desc 'configure alpaca in user wide sence'
      command.arg_name 'node1.node2.property=value', :multiple
      command.command :global do |subcommand|
        subcommand.action do |_, _, arguments|
          Application.new.configure_global(arguments)
        end
      end
    end
  end
end

exit AlpacaBuildTool::GliWrapper.run(ARGV)