Sha256: 9babc70739818060e5381b2888ccc1f80b8c7bbfd5e859d2d213ef6529a36c8d

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

require 'thor'
require 'choria/colt/cli'

module Choria
  class Colt
    # Workaround some, still unfixed, Thor behaviors
    #
    # This class extends ::Thor class to
    # - exit with status code sets to `1` on Thor failure (e.g. missing required option)
    # - exit with status code sets to `1` when user calls `msync` (or a subcommand) without required arguments
    # - show subcommands help using `msync subcommand --help`
    class Thor < ::Thor
      def self.start(*args)
        if (Thor::HELP_MAPPINGS & ARGV).any? && subcommands.none? { |command| command.start_with?(ARGV[0]) }
          Thor::HELP_MAPPINGS.each do |cmd|
            if (match = ARGV.delete(cmd))
              ARGV.unshift match
            end
          end
        end
        super
      end

      desc '_invalid_command_call', 'Invalid command', hide: true
      def _invalid_command_call
        self.class.new.help
        exit 1
      end
      default_task :_invalid_command_call

      def self.exit_on_failure?
        true
      end

      def self.is_thor_reserved_word?(word, type) # rubocop:disable Naming/PredicateName
        return false if word == 'run'

        super
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
choria-colt-0.8.1 lib/choria/colt/cli/thor.rb
choria-colt-0.8.0 lib/choria/colt/cli/thor.rb
choria-colt-0.7.0 lib/choria/colt/cli/thor.rb
choria-colt-0.6.0 lib/choria/colt/cli/thor.rb
choria-colt-0.5.1 lib/choria/colt/cli/thor.rb
choria-colt-0.5.0 lib/choria/colt/cli/thor.rb
choria-colt-0.4.0 lib/choria/colt/cli/thor.rb
choria-colt-0.3.0 lib/choria/colt/cli/thor.rb
choria-colt-0.2.0 lib/choria/colt/cli/thor.rb
choria-colt-0.1.1 lib/choria/colt/cli/thor.rb
choria-colt-0.1.0 lib/choria/colt/cli/thor.rb