Class: Ashiba::Cli
- Inherits:
-
Thor
- Object
- Thor
- Ashiba::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/ashiba/cli.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#packdata ⇒ Object
Returns the value of attribute packdata.
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
-
.source_root ⇒ Object
add_runtime_options!.
Instance Method Summary collapse
- #__print_version ⇒ Object
- #create(template, path) ⇒ Object
- #info(template) ⇒ Object
- #list ⇒ Object
- #locations ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
48 49 50 |
# File 'lib/ashiba/cli.rb', line 48 def config @config end |
#packdata ⇒ Object
Returns the value of attribute packdata.
45 46 47 |
# File 'lib/ashiba/cli.rb', line 45 def packdata @packdata end |
Class Method Details
.exit_on_failure? ⇒ Boolean
34 35 36 |
# File 'lib/ashiba/cli.rb', line 34 def self.exit_on_failure? true end |
.source_root ⇒ Object
add_runtime_options!
29 30 31 32 |
# File 'lib/ashiba/cli.rb', line 29 def self.source_root # File.dirname(__FILE__) File.('../../templates', __dir__) end |
Instance Method Details
#__print_version ⇒ Object
40 41 42 |
# File 'lib/ashiba/cli.rb', line 40 def __print_version say "Ashiba #{VERSION} (Ruby #{RUBY_VERSION}-#{RUBY_PLATFORM})" end |
#create(template, path) ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/ashiba/cli.rb', line 172 def create(template, path) path = File.(path) raise Error, set_color("ERROR: #{path} already exists.", :red) if File.exist?(path) @path = path parse_template_data(template) copy_template(template, path) end |
#info(template) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/ashiba/cli.rb', line 211 def info(template) load_data_from_userconfig template_info = get_data_from_template(template) output = <<~OUTPUT Name : #{template_info['name']} Version : #{template_info['version']} Description: #{template_info['description'].chop} Origin : #{template_info['origin']} Variables: OUTPUT say output align_to = template_info['variables'].keys.map(&:length).max # { |item| item.length }.max template_info['variables'].each do |name, default| default = '<unset>' if default.empty? || default == :mandatory outline = " #{name.ljust(align_to)}: " outline << "#{@config.settings[name]} (was: #{default})" if config.settings[name] outline << default unless config.settings[name] say outline end end |
#list ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/ashiba/cli.rb', line 182 def list # @todo Should be in TemplateLoader dirs = TemplateLoader.new.locations entries = [] dirs.each do |dir| yamls = Dir.glob('*.yaml', base: dir) basenames = yamls.map { |filename| filename.gsub(/\.yaml$/, '') } entries.concat(basenames) end say 'Available templates:' entries.uniq.sort.each do |template| data = get_data_from_template(template) say " #{data['name']} (#{data['version']}) - #{data['summary']}" end end |
#locations ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/ashiba/cli.rb', line 201 def locations dirs = TemplateLoader.new.locations say 'Locations searched for templates' dirs.each do |dir| say " #{dir}" end end |