File: cli.rb

package info (click to toggle)
ruby-semver-dialects 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 156 kB
  • sloc: ruby: 1,537; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 973 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'thor'

module SemverDialects
  # Handle the application command line parsing
  # and the dispatch to various command objects
  #
  # @api public
  class CLI < Thor
    # Error raised by this runner
    Error = Class.new(StandardError)

    desc 'version', 'semver_dialects version'
    def version
      require_relative 'version'
      puts "v#{SemverDialects::VERSION}"
    end
    map %w[--version -v] => :version

    desc 'check_version TYPE VERSION CONSTRAINT', 'Command description...'
    method_option :help, aliases: '-h', type: :boolean,
                         desc: 'Display usage information'
    def check_version(type, version, constraint)
      if options[:help]
        invoke :help, ['check_version']
      else
        require_relative 'commands/check_version'
        ecode = SemverDialects::Commands::CheckVersion.new(type, version, constraint, options).execute
        exit(ecode)
      end
    end
  end
end