Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make type an optional argument

  • Loading branch information...
commit deb4208ad86c7ccd8f6cc04c5a7fcd6a65bdca95 1 parent 3fc3937
Joe Fiorini authored
2  README.markdown
View
@@ -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).
6 lib/projit/cli.rb
View
@@ -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
21 lib/projit/project_generator.rb
View
@@ -9,19 +9,18 @@ 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)
@@ -29,7 +28,7 @@ def in_project_root(&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
8 spec/projit/project_generator_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.