Class: Chef::Knife::CookbookGithubCompare
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CookbookGithubCompare
- Defined in:
- lib/chef/knife/cookbook_github_compare.rb
Instance Attribute Summary collapse
-
#cookbook_name ⇒ Object
readonly
Returns the value of attribute cookbook_name.
-
#current_sha ⇒ Object
readonly
Returns the value of attribute current_sha.
-
#github_path ⇒ Object
readonly
Returns the value of attribute github_path.
Instance Method Summary collapse
- #compare_uri ⇒ Object
- #parse_name_args! ⇒ Object
- #run ⇒ Object
- #user_and_branch ⇒ Object
- #visit_or_print(url) ⇒ Object
Instance Attribute Details
#cookbook_name ⇒ Object (readonly)
Returns the value of attribute cookbook_name.
43 44 45 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 43 def cookbook_name @cookbook_name end |
#current_sha ⇒ Object (readonly)
Returns the value of attribute current_sha.
45 46 47 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 45 def current_sha @current_sha end |
#github_path ⇒ Object (readonly)
Returns the value of attribute github_path.
44 45 46 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 44 def github_path @github_path end |
Instance Method Details
#compare_uri ⇒ Object
91 92 93 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 91 def compare_uri "https://github.com/#{@github_path}/compare/#{@current_sha}...#{user_and_branch}" end |
#parse_name_args! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 79 def parse_name_args! if name_args.empty? ui.error("please specify a cookbook to download and install") exit 1 elsif name_args.size > 2 ui.error("USAGE: knife cookbook github compare COOKBOOK [USER/BRANCH] (options)") exit 1 else name_args.first end end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 47 def run extend Chef::Mixin::ShellOut if config[:cookbook_path] Chef::Config[:cookbook_path] = config[:cookbook_path] else config[:cookbook_path] = Chef::Config[:cookbook_path] end @cookbook_name = parse_name_args! @install_path = File.(Array(config[:cookbook_path]).first) @repo = CookbookSCMRepoExtensions.new(@install_path, ui, config) match = @repo.(@cookbook_name).match("Import (.*) version (.*)") @github_path = match[1] @current_sha = match[2] visit_or_print(compare_uri) end |
#user_and_branch ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 95 def user_and_branch if name_args.size > 1 user, branch = name_args.last.split(/[:\/]/) branch ||= 'master' "#{user}:#{branch}" else 'master' end end |
#visit_or_print(url) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/knife/cookbook_github_compare.rb', line 68 def visit_or_print(url) STDOUT.puts url begin gem 'launchy' require 'launchy' Launchy::Browser.new.visit url rescue Gem::LoadError STDERR.puts "Install launchy to automatically open this in the future: `gem install launchy`" end end |