Class: Consular::CLI

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

Overview

The CLI provides the command line interface for Consular. These are interfaced via the consular bin file.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

Source root for Thor to find templates


11
# File 'lib/consular/cli.rb', line 11

def self.source_root; File.expand_path('../../', __FILE__); end

Instance Method Details

#createObject


133
134
135
# File 'lib/consular/cli.rb', line 133

def create
  invoke :edit, [], options
end

#delete(project = nil) ⇒ Object


154
155
156
157
# File 'lib/consular/cli.rb', line 154

def delete(project = nil)
  path = termfile_path(project)
  message_unless_file(path) { remove_file path }
end

#edit(project = nil) ⇒ Object


112
113
114
115
116
117
# File 'lib/consular/cli.rb', line 112

def edit(project = nil)
  type = project && project =~ /\.yml$/ ? 'yml' : 'term'
  path = termfile_path project
  template "templates/example.#{type}.tt", path, :skip => true
  open_in_editor path, options[:editor]
end

#initObject


88
89
90
91
# File 'lib/consular/cli.rb', line 88

def init
  empty_directory Consular.global_path
  template 'templates/consularc.tt', File.join(ENV['HOME'],'.consularc'), :skip => true
end

#listObject


71
72
73
74
75
76
77
78
# File 'lib/consular/cli.rb', line 71

def list
  say "Global scripts available: \n"
  Dir.glob("#{Consular.global_path}/*[^~]").each do |file|
    name  = File.basename(file, '.term')
    title = file_comment(file)
    say "  * #{name} - #{title}"
  end
end

#setup(project = nil) ⇒ Object


58
59
60
61
# File 'lib/consular/cli.rb', line 58

def setup(project = nil)
  path = termfile_path(project)
  message_unless_file(path) { valid_core.new(path).setup! }
end

#start(project = nil) ⇒ Object


33
34
35
36
# File 'lib/consular/cli.rb', line 33

def start(project = nil)
  path = termfile_path(project)
  message_unless_file(path) { valid_core.new(path).process! }
end