Module: BoilerPlater::Cmd
- Defined in:
- lib/cmd.rb
Class Method Summary collapse
- .alias(action, gist_id, name) ⇒ Object
- .alias_create(gist_id, name) ⇒ Object
- .alias_delete(name) ⇒ Object
- .alias_file ⇒ Object
- .aliases ⇒ Object
- .find_alias(name) ⇒ Object
- .list ⇒ Object
- .search(keyword) ⇒ Object
- .show(id) ⇒ Object
- .update_aliases(arr) ⇒ Object
- .use(id, opts) ⇒ Object
Class Method Details
.alias(action, gist_id, name) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/cmd.rb', line 56 def self.alias(action, gist_id, name) result = case action when 'create' then alias_create(gist_id, name) when 'delete' then alias_delete(name=gist_id) when 'list' then return aliases.map { |gist, n| "#{n}: #{gist}" }.join("\n") end "Alias '#{name}' was #{!result ? 'not' : ''}#{action}d." end |
.alias_create(gist_id, name) ⇒ Object
65 66 67 68 |
# File 'lib/cmd.rb', line 65 def self.alias_create(gist_id, name) return if find_alias(name) == gist_id update_aliases(aliases << [gist_id, name]) end |
.alias_delete(name) ⇒ Object
75 76 77 |
# File 'lib/cmd.rb', line 75 def self.alias_delete(name) update_aliases(aliases.delete_if { |k, v| v == name }) end |
.alias_file ⇒ Object
83 84 85 |
# File 'lib/cmd.rb', line 83 def self.alias_file File.join(ENV['HOME'], '.bp_aliases.yaml') end |
.aliases ⇒ Object
79 80 81 |
# File 'lib/cmd.rb', line 79 def self.aliases File.exists?(alias_file) ? YAML::load_file(alias_file) : [] end |
.find_alias(name) ⇒ Object
70 71 72 73 |
# File 'lib/cmd.rb', line 70 def self.find_alias(name) res = aliases.find { |k, v| v == name.strip } res ? res.first : name end |
.list ⇒ Object
24 25 26 |
# File 'lib/cmd.rb', line 24 def self.list BoilerPlater.list.map { |k, v| "#{v}: #{k}" }.join("\n") end |
.search(keyword) ⇒ Object
20 21 22 |
# File 'lib/cmd.rb', line 20 def self.search(keyword) BoilerPlater.search(keyword) end |
.show(id) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/cmd.rb', line 28 def self.show(id) data = BoilerPlater.show(find_alias(id)) "\nDescription: #{data['description']}\n" + "Author: #{data['user']['login']}\n" + "URL: #{data['url']}\n" + "\n" end |
.update_aliases(arr) ⇒ Object
87 88 89 |
# File 'lib/cmd.rb', line 87 def self.update_aliases(arr) File.open(alias_file, 'w') { |f| YAML::dump(arr, f) } end |
.use(id, opts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cmd.rb', line 36 def self.use(id, opts) BoilerPlater.setup do |bp| bp.prefix = opts[:prefix] end id = find_alias(id) puts puts "Setting up new project using %s\n\n" % BoilerPlater.show(id)['description'] BoilerPlater.sections(BoilerPlater.get(id)).each do |part| puts ' [%-8s] %s' % [(part.content? ? 'create '.green : 'download'.yellow), part.path] part.download_content! unless part.content? if part.exists? print ' File already exists, overwrite? [y,N]: ' part.save! if STDIN.gets.chop.strip == 'Y' else part.save! end end "\ndone.\n" end |