Class: Tocer::CLI

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



23
24
25
# File 'lib/tocer/cli.rb', line 23

def initialize args = [], options = {}, config = {}
  super args, options, config
end

Class Method Details

.configurationObject



16
17
18
19
20
21
# File 'lib/tocer/cli.rb', line 16

def self.configuration
  Runcom::Configuration.new file_name: Identity.file_name, defaults: {
    label: "# Table of Contents",
    whitelist: %w[.md]
  }
end

Instance Method Details

#configObject



61
62
63
64
65
66
67
68
# File 'lib/tocer/cli.rb', line 61

def config
  path = self.class.configuration.computed_path

  if options.edit? then `#{editor} #{path}`
  elsif options.info? then say(path)
  else help(:config)
  end
end

#generate(path) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tocer/cli.rb', line 39

def generate path
  configuration = build_configuration path, options.label, options.whitelist
  runner = build_runner path, configuration
  files = runner.files

  runner.run
  return if files.empty?

  say "Processed table of contents for:"
  files.each { |file| say "  #{file}" }
end

#help(task = nil) ⇒ Object



78
79
80
# File 'lib/tocer/cli.rb', line 78

def help task = nil
  say and super
end

#versionObject



72
73
74
# File 'lib/tocer/cli.rb', line 72

def version
  say Identity.version_label
end