Browse files

Make type an optional argument

  • Loading branch information...
1 parent 3fc3937 commit deb4208ad86c7ccd8f6cc04c5a7fcd6a65bdca95 @joefiorini committed Nov 23, 2011
Showing with 24 additions and 13 deletions.
  1. +1 −1 README.markdown
  2. +3 −3 lib/projit/cli.rb
  3. +14 −7 lib/projit/project_generator.rb
  4. +6 −2 spec/projit/project_generator_spec.rb
View
2 README.markdown
@@ -18,7 +18,7 @@ This will run the recipe you have installed in `~/.projit/template.rb`. To get t
This will run the same recipe but also clone the specified git repository (assuming you have `clone_from_git` in your recipe).
- projit new personal/projit\_demo --type screencast
+ projit new screencast personal/projit_demo
Runs the recipe stored in `~/.projit/screencast.rb` to setup a directory structure for screencasting. To get the generator that I use for screencasting download [this gist][screencasting] (structure stolen from @topfunky).
View
6 lib/projit/cli.rb
@@ -4,9 +4,9 @@
module Projit
class CLI < Thor
- desc "new NAME", "Create project named NAME under current directory or CLIENT if specified"
- class_options git: nil, type: nil
- def new(name)
+ desc "new TYPE NAME", "Create project named NAME under current directory using the template specified by TYPE"
+ class_options git: nil
+ def new(type, name=nil)
args = ARGV.reject { |a| a == "new" }
Projit::ProjectGenerator.start args
end
View
21 lib/projit/project_generator.rb
@@ -9,27 +9,26 @@ class ProjectGenerator < Thor::Group
source_root "~/.projit"
- argument :project
+ argument :type, default: "template"
+ argument :project, required: false
class_options git: nil
- class_option :type, default: "template"
def new
apply projit_template
end
-
protected
def projit_template
- "#{options[:type]}.rb"
+ "#{template_name}.rb"
end
def in_project_root(&block)
inside projects_home.to_s, &block
end
def in_project_directory(&block)
- inside projects_home_path.join(project), &block
+ inside projects_home_path.join(project_name), &block
end
def create_link_in_dropbox(name)
@@ -56,11 +55,19 @@ def clone_from_git_into(name)
end
def project_path
- Pathname.new project
+ Pathname.new project_name
+ end
+
+ def project_name
+ project || type
+ end
+
+ def template_name
+ (project && type) || "template"
end
def project_full_path
- projects_home_path.join(project)
+ projects_home_path.join(project_name)
end
def project_base
View
8 spec/projit/project_generator_spec.rb
@@ -102,10 +102,14 @@
end
context "support project types" do
- it "uses type parameter to find the template script" do
- subject.stub(options: { type: "web_application" })
+ it "uses type argument to find the template script" do
+ subject.stub(type: "web_application")
subject.send(:projit_template).should eq "web_application.rb"
end
+ it "uses type argument for project name if name isn't specified" do
+ subject.stub(type: "project", name: nil)
+ subject.send(:project_name).should eq "project"
+ end
end
end

0 comments on commit deb4208

Please sign in to comment.