Class: Milestoner::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/milestoner/cli.rb

Overview

The Command Line Interface (CLI) for the gem.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
28
29
30
# File 'lib/milestoner/cli.rb', line 22

def initialize args = [], options = {}, config = {}
  super args, options, config
  @configuration = self.class.configuration
  @tagger = Tagger.new commit_prefixes: @configuration.to_h[:git_commit_prefixes]
  @pusher = Pusher.new
  @publisher = Publisher.new tagger: tagger, pusher: pusher
rescue Runcom::Errors::Base => error
  abort error.message
end

Class Method Details

.configurationObject



14
15
16
17
18
19
20
# File 'lib/milestoner/cli.rb', line 14

def self.configuration
  Runcom::Configuration.new project_name: Identity.name, defaults: {
    version: "0.1.0",
    git_commit_prefixes: %w[Fixed Added Updated Removed Refactored],
    git_tag_sign: false
  }
end

Instance Method Details

#commitsObject



34
35
36
37
38
# File 'lib/milestoner/cli.rb', line 34

def commits
  tagger.commit_list.each { |commit| say commit }
rescue StandardError => exception
  say_status :error, exception.message, :red
end

#configObject



88
89
90
91
92
93
94
95
96
# File 'lib/milestoner/cli.rb', line 88

def config
  path = configuration.path

  if options.edit? then `#{ENV["EDITOR"]} #{path}`
  elsif options.info?
    path ? say(path) : say("Configuration doesn't exist.")
  else help(:config)
  end
end

#help(task = nil) ⇒ Object



106
107
108
# File 'lib/milestoner/cli.rb', line 106

def help task = nil
  say and super
end

#publish(version = ) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/milestoner/cli.rb', line 70

def publish version = configuration.to_h[:version]
  publisher.publish version, sign: sign_tag?(options[:sign])
  say_status :info, "Repository tagged and pushed: #{tagger.version_label}.", :green
  say_status :info, "Milestone published!", :green
rescue StandardError => exception
  say_status :error, exception.message, :red
end

#push(version = ) ⇒ Object



56
57
58
59
60
61
# File 'lib/milestoner/cli.rb', line 56

def push version = configuration.to_h[:version]
  pusher.push version
  say_status :info, "Tags pushed to remote repository.", :green
rescue StandardError => exception
  say_status :error, exception.message, :red
end

#tag(version = ) ⇒ Object



47
48
49
50
51
52
# File 'lib/milestoner/cli.rb', line 47

def tag version = configuration.to_h[:version]
  tagger.create version, sign: sign_tag?(options[:sign])
  say "Repository tagged: #{tagger.version_label}."
rescue StandardError => exception
  say_status :error, exception.message, :red
end

#versionObject



100
101
102
# File 'lib/milestoner/cli.rb', line 100

def version
  say Identity.version_label
end