Class: Pragmater::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/pragmater/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.



28
29
30
31
32
33
# File 'lib/pragmater/cli.rb', line 28

def initialize args = [], options = {}, config = {}
  super args, options, config
  @configuration = self.class.configuration
rescue Runcom::Errors::Base => error
  abort error.message
end

Class Method Details

.configurationObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pragmater/cli.rb', line 15

def self.configuration
  Runcom::Configuration.new project_name: Identity.name, defaults: {
    add: {
      comments: "",
      includes: []
    },
    remove: {
      comments: "",
      includes: []
    }
  }
end

Instance Method Details

#add(path = ".") ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pragmater/cli.rb', line 47

def add path = "."
  settings = configuration.merge add: {
    comments: options[:comments],
    includes: options[:includes]
  }

  runner = Runner.new path,
                      comments: settings.dig(:add, :comments),
                      includes: settings.dig(:add, :includes)

  runner.run(action: :add) { |file| say_status :info, "Processed: #{file}.", :green }
end

#configObject



95
96
97
98
99
100
101
102
103
# File 'lib/pragmater/cli.rb', line 95

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



113
114
115
# File 'lib/pragmater/cli.rb', line 113

def help task = nil
  say and super
end

#remove(path = ".") ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pragmater/cli.rb', line 72

def remove path = "."
  settings = configuration.merge remove: {
    comments: options[:comments],
    includes: options[:includes]
  }

  runner = Runner.new path,
                      comments: settings.dig(:remove, :comments),
                      includes: settings.dig(:remove, :includes)

  runner.run(action: :remove) { |file| say_status :info, "Processed: #{file}.", :green }
end

#versionObject



107
108
109
# File 'lib/pragmater/cli.rb', line 107

def version
  say Identity.version_label
end