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
# File 'lib/pragmater/cli.rb', line 28

def initialize args = [], options = {}, config = {}
  super args, options, config
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: "",
      whitelist: []
    },
    remove: {
      comments: "",
      whitelist: []
    }
  }
end

Instance Method Details

#add(path = ".") ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pragmater/cli.rb', line 44

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

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

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

#configObject



92
93
94
95
96
97
98
99
100
# File 'lib/pragmater/cli.rb', line 92

def config
  path = self.class.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



110
111
112
# File 'lib/pragmater/cli.rb', line 110

def help task = nil
  say and super
end

#remove(path = ".") ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pragmater/cli.rb', line 69

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

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

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

#versionObject



104
105
106
# File 'lib/pragmater/cli.rb', line 104

def version
  say Identity.version_label
end