Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Remove --constraints option
Browse files Browse the repository at this point in the history
If a version constraint is specified in metadata.rb, it should always be
reflected in README.md.
  • Loading branch information
mlafeldt committed Sep 25, 2013
1 parent c6ab6b8 commit 2b69664
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 81 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ Usage

knife cookbook readme from FILE (options)

-c, --constraints Include version constraints for platforms and dependencies
-t, --template FILE Set template file used to render README.md

Examples:

knife cookbook readme from path/to/metadata.rb
knife cookbook readme from path/to/metadata.rb --constraints >README.md
knife cookbook readme from path/to/metadata.rb --template README.md.erb


Expand Down
11 changes: 1 addition & 10 deletions lib/chef/knife/cookbook_readme_from.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ class CookbookReadmeFrom < Chef::Knife

banner 'knife cookbook readme from FILE (options)'

option :constraints,
:short => '-c',
:long => '--constraints',
:boolean => true,
:default => false,
:description => 'Include version constraints for platforms and dependencies'

option :template_file,
:short => '-t',
:long => '--template FILE',
Expand All @@ -26,7 +19,6 @@ class CookbookReadmeFrom < Chef::Knife
def run
metadata_file = name_args.first
template_file = config[:template_file]
constraints = config[:constraints]

unless metadata_file
ui.fatal 'Please provide metadata.rb file as argument'
Expand All @@ -35,8 +27,7 @@ def run

metadata = Metadata.from_file(metadata_file)
template = File.read(template_file)
readme = Readme.new(metadata, constraints)
result = readme.render(template)
result = Readme.new(metadata).render(template)

ui.output(result)
end
Expand Down
5 changes: 2 additions & 3 deletions lib/knife_cookbook_readme/readme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module KnifeCookbookReadme
DEFAULT_CONSTRAINT = ">= 0.0.0".freeze

class Readme
def initialize(metadata, constraints=false)
def initialize(metadata)
@metadata = metadata
@constraints = constraints
end

def title
Expand Down Expand Up @@ -61,7 +60,7 @@ def render(template)
private

def format_constraint(name, version)
if @constraints && version != DEFAULT_CONSTRAINT
if version && version != DEFAULT_CONSTRAINT
"#{name} (#{version})"
else
name
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/mysql-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Requirements
### Cookbooks:

* openssl
* build-essential
* build-essential (> 1.1.0)

Attributes
----------
Expand Down
104 changes: 39 additions & 65 deletions spec/readme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ module KnifeCookbookReadme
readme.description.should == description
end

it "generates recipes" do
recipes = double
metadata = double(:metadata, :recipes => recipes)
it "generates supported platforms" do
platforms = { "debian" => "= 7", "ubuntu" => ">= 10.04" }
metadata = double(:metadata, :platforms => platforms)
readme = Readme.new(metadata)
readme.recipes.should == recipes
readme.platforms.should == ["Debian (= 7)", "Ubuntu (>= 10.04)"]
end

it "generates cookbook dependencies" do
dependencies = { "cats" => "< 1.0", "dogs" => DEFAULT_CONSTRAINT }
metadata = double(:metadata, :dependencies => dependencies)
readme = Readme.new(metadata)
readme.dependencies.should == ["cats (< 1.0)", "dogs"]
end

it "generates cookbook attributes" do
Expand All @@ -42,73 +49,40 @@ module KnifeCookbookReadme
]
end

context "supported platforms" do
let(:metadata) do
platforms = { "debian" => "= 7", "ubuntu" => ">= 10.04" }
double(:metadata, :platforms => platforms)
end

it "generates platforms with version constraints" do
constraints = true
readme = Readme.new(metadata, constraints)
readme.platforms.should == ["Debian (= 7)", "Ubuntu (>= 10.04)"]
end

it "generates platforms without version constraints" do
constraints = false
readme = Readme.new(metadata, constraints)
readme.platforms.should == ["Debian", "Ubuntu"]
end
it "generates recipes" do
recipes = double
metadata = double(:metadata, :recipes => recipes)
readme = Readme.new(metadata)
readme.recipes.should == recipes
end

context "cookbook dependencies" do
let(:metadata) do
dependencies = { "cats" => "< 1.0", "dogs" => DEFAULT_CONSTRAINT }
double(:metadata, :dependencies => dependencies)
end

it "generates dependencies with version constraints" do
constraints = true
readme = Readme.new(metadata, constraints)
readme.dependencies.should == ["cats (< 1.0)", "dogs"]
end

it "generates dependencies without version constraints" do
constraints = false
readme = Readme.new(metadata, constraints)
readme.dependencies.should == ["cats", "dogs"]
end
it "generates author from maintainer name" do
maintainer = double
metadata = double(:metadata, :maintainer => maintainer)
readme = Readme.new(metadata)
readme.author.should == maintainer
end

context "license and author" do
it "generates author from maintainer name" do
maintainer = double
metadata = double(:metadata, :maintainer => maintainer)
readme = Readme.new(metadata)
readme.author.should == maintainer
end
it "generates author email from maintainer email" do
maintainer_email = double
metadata = double(:metadata, :maintainer_email => maintainer_email)
readme = Readme.new(metadata)
readme.author_email.should == maintainer_email
end

it "generates author email from maintainer email" do
maintainer_email = double
metadata = double(:metadata, :maintainer_email => maintainer_email)
readme = Readme.new(metadata)
readme.author_email.should == maintainer_email
end
it "generates copyright year from current year" do
time_now = Time.mktime(2013, 1, 1)
Time.stub(:now).and_return(time_now)
metadata = double
readme = Readme.new(metadata)
readme.copyright_year.should == time_now.year
end

it "generates copyright year from current year" do
time_now = Time.mktime(2013, 1, 1)
Time.stub(:now).and_return(time_now)
metadata = double
readme = Readme.new(metadata)
readme.copyright_year.should == time_now.year
end

it "generates license name" do
license = double
metadata = double(:metadata, :license => license)
readme = Readme.new(metadata)
readme.license.should == license
end
it "generates license name" do
license = double
metadata = double(:metadata, :license => license)
readme = Readme.new(metadata)
readme.license.should == license
end

context "#render" do
Expand Down

0 comments on commit 2b69664

Please sign in to comment.