Class: Cheflow::Cli
- Inherits:
-
Thor
- Object
- Thor
- Cheflow::Cli
- Defined in:
- lib/cheflow/cli.rb
Constant Summary collapse
- LATEST =
"latest".freeze
Instance Method Summary collapse
- #apply(environment_name) ⇒ Object
- #bump(level = 'patch') ⇒ Object
- #default ⇒ Object
- #info ⇒ Object
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #outdated(*names) ⇒ Object
- #update(*cookbook_names) ⇒ Object
- #upload ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
14 15 16 17 18 19 |
# File 'lib/cheflow/cli.rb', line 14 def initialize(*args) super(*args) Ridley.logger.level = ::Logger::INFO if [:verbose] Ridley.logger.level = ::Logger::DEBUG if [:debug] end |
Instance Method Details
#apply(environment_name) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cheflow/cli.rb', line 83 def apply(environment_name) unless cookbook.node_cookbook? say "Cannot apply Non-Node Cookbooks. Run this again for a Node Cookbook", :red exit(1) end lockfile = File.join(cookbook.path, Berkshelf::Lockfile::DEFAULT_FILENAME) unless File.exist?(lockfile) say "No lockfile found at #{lockfile}", :red exit(1) end full_environment_name = "node_#{cookbook.node_name}" full_environment_name += "_#{environment_name}" if environment_name != 'production' say "Applying Node Cookbook #{cookbook} and its dependencies to #{environment_name} (#{full_environment_name})", :bold if environment_name == 'production' exit(1) unless yes?('Are you sure you wish to apply locked versions to production?', :red) end lockfile = Berkshelf::Lockfile.from_file(lockfile) begin unless lockfile.apply(full_environment_name) error "Failed to apply locked versions" exit(1) end rescue Berkshelf::EnvironmentNotFound => e say "Unable to apply locked versions. #{e}", :red exit(1) end end |
#bump(level = 'patch') ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cheflow/cli.rb', line 132 def bump(level='patch') from = cookbook.version major, minor, patch = from.major, from.minor, from.patch binding.eval("#{level} = #{from.send(level)+1}") to = "#{major}.#{minor}.#{patch}" version_file = File.join(cookbook.path, 'VERSION') if File.exist? version_file File.open(version_file, 'w') { |file| file.puts to } say "Bumped #{level} version from #{from} to #{to}", :green else say "The 'VERSION' file does not exist, so cannot bump the #{level} version", :red exit(1) end end |
#default ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/cheflow/cli.rb', line 183 def default invoke :version say say '-' * 90 invoke :info say '-' * 90 say invoke :help end |
#info ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cheflow/cli.rb', line 149 def info say "#{cookbook.type.capitalize} Cookbook: #{cookbook}", :bold say cookbook.path say say "Environments: #{cookbook.node_environments(true).join("\n ")}" pv = cookbook.prod_versions dv = cookbook.dev_versions if dv.count > 0 || pv.count > 0 say say 'Versions: (most recent)' if pv.count > 0 if pv.count > 10 say " Production: #{pv[0,10].join(', ')} (...)" else say " Production: #{pv.join(', ')}" end end if dv.count > 0 if dv.count > 10 say " Development: #{dv[0,10].join(', ')} (...)" else say " Development: #{dv.join(', ')}" end end say end end |
#outdated(*names) ⇒ Object
77 78 79 80 |
# File 'lib/cheflow/cli.rb', line 77 def outdated(*names) outdated = cookbook.berksfile.outdated(*names) Berkshelf.formatter.outdated(outdated) end |
#update(*cookbook_names) ⇒ Object
72 73 74 |
# File 'lib/cheflow/cli.rb', line 72 def update(*cookbook_names) cookbook.berksfile.update *cookbook_names end |
#upload ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/cheflow/cli.rb', line 61 def upload say "Uploading #{cookbook.type} Cookbook: #{cookbook}" begin cookbook.upload rescue Ridley::Errors::FrozenCookbook => e say e, :red exit(1) end end |
#version ⇒ Object
117 118 119 |
# File 'lib/cheflow/cli.rb', line 117 def version say "Cheflow v#{Cheflow::VERSION}" end |