nake 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ = Version 0.0.1
2
+ * bin/nake executable
3
+ * sh helper (nake/helpers)
4
+ * task helper (nake/dsl)
5
+ * Task with description, dependencies and blocks
6
+ * Hidden tasks
7
+ * Each task can has multiple aliases
8
+ * Command line arguments parsing. Arguments will be passed as an arguments for blocks of the given task and options will be extracted into a hash, parsed into Ruby data types and passed as the last argument for the blocks.
9
+ * Default tasks for help (-H, --help), list of available tasks (-T, --tasks) and interactive session (-i, --interactive)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 – 2010 Jakub Šťastný aka Botanicus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ h1. About
2
+
3
+ Nake is light-weight and highly flexible Rake replacement with much better arguments parsing.
4
+
5
+ You might be wondering why to write yet another fucking task manager when we have Rake, Thor and others. Well, because all of them sucks. For example Rake, anyone is actually using its CLI arguments, because it sucks so much, that everyone rather write @ENV=test VERSION=10 rake db:migrate@. It has not just shitty API for defining CLI arguments, but also it is using very weird and totally non-unix syntax like @rake db:migrate[test,10]@. This syntax isn't just non-standard, but also some shells has @[]@ as special characters, so you actually has to escape it.
6
+
7
+ Sounds terrible? Well and it's not all! Let's take a look at this "example":http://gist.github.com/263325, as you can see if you have argument path and you let it empty, than it takes environment variable @$PATH@! I contact Jim Weirich about this issue and he never replied, so he probably thinks it's fine. Fair enough, but I won't work with such tool.
8
+
9
+ h1. Features
10
+
11
+ - Tasks can have a *name*, *description*, *dependencies*, *aliases* and *blocks* which will be executed when the task is called. Task can be also hidden if you don't want to list it in the list of available tasks.
12
+ - You can use `nake` in *shebang*, so you can use your file with tasks as a runner.
13
+ - *Arguments parsing*, everything what start with @--@ will be passed into options hash and everything other will be treated as an arguments. Both arguments and options will be passed as a block arguments for task, so you don't have to learn any new API, just use normal Ruby expressions as you are used to. Options are parsed into Ruby data types, so if you have @--without-mysql@, you'll get @{mysql: false}@, if you have @--name=botanicus@, you'll get @{name: "botanicus"}@ etc.
14
+ - *Arbitrary names of tasks* is one of the key features of Nake. This way you can *namespace* your tasks (like @nake build:prerelease@) or you can define tasks like @-T@.
15
+ - Two level of API for defining tasks. @task@ helper is useful for defining simple tasks and if you need something more complicated, you can use @Task.new@
16
+ - *Interactive session* if you run @nake -i@ or @nake -i task@ you get an interactive nake session.
17
+
18
+ h1. Usage
19
+
20
+ First of all there is a bunch of "examples":github.com/botanicus/nake/tree/master/examples, so you can try them. All these scripts are executable, so just run @./executable/basic.rb -T@ and that's it!
21
+
22
+ h1. Links
23
+
24
+ - http://github.com/botanicus/filelist
@@ -0,0 +1,7 @@
1
+ - fix interactive task, it doesn't work so far
2
+ - better argv parsing maybe, task(:spec) do |*paths, options| is fine, but task(:spec) do |path, options| will fail if no path specified ... but actually task(:spec) do |path = "spec", options| might be fine, try it ... BTW task(["-i", "--interactive"]) do |task, *args, options| doesn't work ... putting options as a first argument should solve everything, but it's not very intuitive :/
3
+ - it might be worthy to steal filelist from Rake
4
+ - how to solve args inheriting (like if we have task release which depends on task build which takes a gemspec as an argument)
5
+ - benchmarks against rake
6
+ - maybe some of: fileutils extensions, multitask, rule, file, directory (from rake, see http://rake.rubyforge.org/files/doc/rakefile_rdoc.html)
7
+ - some default tasks like nake/tasks/package, nake/tasks/clean, nake/tasks/yardoc, nake/tasks/spec, nake/tasks/bundle
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require "nake"
6
+
7
+ # First argument has to be path to file with your tasks
8
+ load ARGV.first
9
+
10
+ # Parse arguments and run tasks
11
+ begin
12
+ Nake.run(ARGV[1..-1])
13
+ rescue TaskNotFound => exception
14
+ abort "[#{"ERROR".red}] #{exception.message}"
15
+ end
@@ -0,0 +1,5 @@
1
+ #!./bin/nake
2
+
3
+ task(:greet2) do |user = ENV["USER"]|
4
+ puts "Hi #{user}!"
5
+ end
@@ -0,0 +1,7 @@
1
+ #!./bin/nake
2
+
3
+ # simple
4
+ task(:greet1) do
5
+ puts "Hi #{ENV["USER"]}!"
6
+ end
7
+
@@ -0,0 +1,9 @@
1
+ #!./bin/nake
2
+
3
+ Task.new(:release) do |task|
4
+ task.description = "Just release it"
5
+ task.dependencies.clear # redefine
6
+ task.block do |*args|
7
+
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ #!./bin/nake
2
+
3
+ # When you run rake without arguments, it will try to run task called default.
4
+ # Since I don't believe in any stupid convention, I don't support anything similar,
5
+ # because you can do it just using standard Ruby methods like Hash#default=(value)
6
+ # Of course the task which you are assigning as a default have to already exist,
7
+ # so you have to put this to the end of your file or you might want to use
8
+ # Hash#default_proc=(proc) as described in examples/default_proc.rb like:
9
+ # Task.tasks.default_proc = lambda { |*| Task[:build] }
10
+ Task.tasks.default = Task["-T"]
@@ -0,0 +1,11 @@
1
+ #!./bin/nake
2
+
3
+ # Default value returned from Task["not_existing_task"] don't have to be even a task,
4
+ # it just have to respond to #call, so you can use Hash#default_proc=(proc) as well
5
+ # Just make sure you are wrap the callable object in lambda, because the callable
6
+ # object has to be returned as a result from the finding on the hash, but the
7
+ # default proc is what is actually called if nothing is found.
8
+ # You might i. e. customize error message or you might detect desired task in runtime.
9
+ Task.tasks.default_proc = lambda do |tasks, name|
10
+ lambda { |*args| abort("Task #{name} executed with args: #{args.inspect}") }
11
+ end
@@ -0,0 +1,4 @@
1
+ #!./bin/nake
2
+
3
+ task = task(:greet3, :greet1, :greet2)
4
+ task.description = "Run greet1 & greet2"
@@ -0,0 +1,3 @@
1
+ #!./bin/nake
2
+
3
+ task(:ls) { sh "ls" }.description = "List available files"
@@ -0,0 +1,5 @@
1
+ #!./bin/nake
2
+
3
+ task(:foo) do
4
+ Task[:bar].call
5
+ end
@@ -0,0 +1,6 @@
1
+ #!./bin/nake
2
+
3
+ # ./examples/options.rb greet2 --name=botanicus
4
+ task(:greet2) do |options|
5
+ puts "Hi #{options[:name]}!"
6
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby --disable-gems
2
+
3
+ # This file shows how to run Nake from API. In most of cases you don't
4
+ # need this and you might want to use just shebang with env, but this
5
+ # might come handy if you need to pass some arguments for Ruby.
6
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
7
+
8
+ require "nake"
9
+
10
+ # task definitions
11
+ task("greet:all") do
12
+ puts "Hey guys!"
13
+ end
14
+
15
+ # run nake
16
+ begin
17
+ Nake.run(ARGV)
18
+ rescue TaskNotFound => exception
19
+ abort "[#{"ERROR".red}] #{exception.message}"
20
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require "nake/argv"
4
+ require "nake/task"
5
+
6
+ module Nake
7
+ VERSION ||= "0.0.1"
8
+ TaskNotFound ||= Class.new(StandardError)
9
+
10
+ def self.run(args = ARGV)
11
+ name = args.shift
12
+ task = Task[name]
13
+ if name && task.nil?
14
+ raise TaskNotFound, "Task with name #{name} doesn't exist"
15
+ elsif name.nil? && task.nil?
16
+ raise TaskNotFound, "You have to specify a task you want to run!"
17
+ end
18
+ opts = args.extend(ArgvParsingMixin).extract!
19
+ task.call(args, opts)
20
+ end
21
+ end
22
+
23
+ require "nake/dsl"
24
+ require "nake/helpers"
25
+ require "nake/tasks"
26
+ require "nake/colors"
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module Nake
4
+ module ArgvParsingMixin
5
+ def extract!
6
+ self.inject(Hash.new) do |options, argument|
7
+ case argument
8
+ when /^--no-([^=]+)$/ # --no-git-repository
9
+ options[$1.gsub("-", "_").to_sym] = false
10
+ self.delete(argument)
11
+ when /^--([^=]+)$/ # --git-repository
12
+ options[$1.gsub("-", "_").to_sym] = true
13
+ self.delete(argument)
14
+ when /^--([^=]+)=([^,]+)$/ # --controller=post
15
+ key, value = $1, $2
16
+ options[key.gsub("-", "_").to_sym] = value.dup
17
+ self.delete(argument)
18
+ when /^--([^=]+)=(.+)$/ # --controllers=posts,comments
19
+ key, value = $1, $2
20
+ options[key.gsub("-", "_").to_sym] = value.split(",")
21
+ self.delete(argument)
22
+ else
23
+ # just extract options and ignore others
24
+ end
25
+ options
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require "term/ansicolor"
5
+ rescue LoadError
6
+ raise LoadError, "You have to install term-ansicolor gem!"
7
+ end
8
+
9
+ String.send(:include, Term::ANSIColor) # just for now, I know it's a mess
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require "nake/task"
4
+
5
+ class Object
6
+ include Nake
7
+ # Rake-style task definition
8
+ # task(:release, :build) do |task|
9
+ # # task definition
10
+ # end
11
+ def task(name, *dependencies, &block)
12
+ if block.nil?
13
+ Task.new(name, *dependencies)
14
+ else
15
+ Task.new(name, *dependencies) do |task|
16
+ task.define(&block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require "fileutils"
4
+ require "open3"
5
+
6
+ module Nake
7
+ module TaskHelpers
8
+ include FileUtils
9
+ def sh(command)
10
+ puts "#{"$".magenta} #{command.cyan}"
11
+ Open3.popen3("sh", "-c", command) do |stdin, stdout, stderr|
12
+ puts stdout.readlines.map { |line| " #{line}" }
13
+ puts stderr.readlines.map { |line| " #{line.red}" }
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Object.send(:include, Nake::TaskHelpers)
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ require "nake/colors"
4
+
5
+ module Nake
6
+ class Task
7
+ def self.[](name)
8
+ name = name.to_s
9
+ self.tasks[name] || self.find_in_aliases(name)
10
+ end
11
+
12
+ # @private
13
+ def self.find_in_aliases(name)
14
+ _, task = self.tasks.find { |_, task| task.aliases.include?(name) }
15
+ return task
16
+ end
17
+
18
+ def self.[]=(name, task)
19
+ self.tasks[name.to_s] = task
20
+ end
21
+
22
+ # @protected use Task[name] resp. Task[name] = task
23
+ def self.tasks
24
+ @@tasks ||= Hash.new
25
+ end
26
+
27
+ # return existing task if task with given name already exist
28
+ def self.new(name, *dependencies, &block)
29
+ task = self[name]
30
+ task && task.setup(*dependencies, &block) || super(name, *dependencies, &block)
31
+ end
32
+
33
+ attr_accessor :name, :description, :dependencies, :hidden, :options
34
+ attr_reader :blocks, :aliases
35
+ def initialize(name, *dependencies, &block)
36
+ @aliases, @hidden = Array.new, false
37
+ # This is a bit weird, but it's best solution
38
+ # when we want to keep API simple and keep it
39
+ # as one object even if it has more names
40
+ if name.respond_to?(:join) # array
41
+ name, *aliases = name
42
+ self.aliases.push(*aliases)
43
+ end
44
+ @name, @blocks = name.to_sym, Array.new
45
+ @dependencies = Array.new
46
+ self.register
47
+ self.setup(*dependencies, &block)
48
+ end
49
+
50
+ def setup(*dependencies, &block)
51
+ self.dependencies.push(*dependencies)
52
+ self.instance_exec(self, &block) if block
53
+ return self
54
+ end
55
+
56
+ def define(&block)
57
+ @blocks.push(block)
58
+ end
59
+
60
+ def hidden?
61
+ @hidden
62
+ end
63
+
64
+ # NOTE: the reason why we don't have splat for args is that when we have Task["-T"]
65
+ # which doesn't have any args and options, we wall just call it without any arguments,
66
+ # but when we use splat, then we will have to call it at least with Hash.new for options
67
+ def call(args = Array.new, options = Hash.new)
68
+ unless @dependencies.empty?
69
+ puts "~ Invoking task #{name}".cyan
70
+ self.invoke_dependencies(*args, options)
71
+ end
72
+ unless @blocks.empty?
73
+ puts "~ Executing task #{name} with arguments #{args.inspect} and options #{options.inspect}".green
74
+ @blocks.each do |block|
75
+ if block.arity.eql?(0)
76
+ block.call
77
+ else
78
+ block.call(*args, options)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ protected
85
+ def invoke_dependencies(*args, options)
86
+ self.dependencies.each do |name|
87
+ task = self.class[name]
88
+ raise TaskNotFound, "Task with name #{name} doesn't exist" if task.nil?
89
+ task.call(*args, options) # TODO: what about arguments?
90
+ end
91
+ end
92
+
93
+ def register
94
+ self.class[self.name] = self
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require "nake/dsl"
4
+
5
+ task(["-H", "--help"]) do
6
+ abort "\nUse #{$0} -T for list of all available tasks or -i for interactive session"
7
+ end
8
+
9
+ task(["-T", "--tasks"]) do |pattern, options = Hash.new|
10
+ tasks, options = Task.tasks.select { |name, task| not task.hidden? }.sort.partition { |key, value| not key.match(/^-/) }
11
+
12
+ puts "\n#{"===".yellow} #{"Available tasks".magenta} #{"===".yellow}"
13
+ if tasks.empty?
14
+ puts "No tasks defined"
15
+ else
16
+ tasks.each do |name, task|
17
+ puts "#{name.green} #{task.dependencies.join(", ")} # #{task.description || "no description yet"}"
18
+ end
19
+ end
20
+
21
+ puts "\n#{"===".yellow} #{"Available options".magenta} #{"===".yellow}"
22
+ if options.empty?
23
+ puts "No options defined"
24
+ else
25
+ options.each do |name, task|
26
+ puts "#{name.green} #{task.dependencies.join(", ")} # #{task.description || "no description yet"}"
27
+ end
28
+ end
29
+ end
30
+
31
+ # TODO: this doesn't work so far
32
+ task(["-i", "--interactive"]) do |*args, options|
33
+ require "irb"
34
+ begin
35
+ require "irb/readline"
36
+ rescue LoadError
37
+ warn "Code completion via readline isn't available"
38
+ end
39
+
40
+ unless args.empty?
41
+ task = Task[args.shift]
42
+ task.call(*args, options)
43
+ end
44
+
45
+ IRB.start
46
+ end
47
+
48
+ Task["-T"].hidden = true
49
+ Task["-H"].hidden = true
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ # NOTE: we can't use require_relative because when we run gem build, it use eval for executing this file
5
+ $:.unshift(File.join(File.dirname(__FILE__), "lib"))
6
+ require "nake"
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "nake"
10
+ s.version = Nake::VERSION
11
+ s.authors = ["Jakub Šťastný aka Botanicus"]
12
+ s.homepage = "http://github.com/botanicus/nake"
13
+ s.summary = "Nake is light-weight and highly flexible Rake replacement with much better arguments parsing"
14
+ s.description = "" # TODO: long description
15
+ s.cert_chain = nil
16
+ s.email = ["knava.bestvinensis", "gmail.com"].join("@")
17
+ s.has_rdoc = true
18
+
19
+ # files
20
+ s.files = Dir.glob("**/*")
21
+ s.executables = ["nake"]
22
+ s.default_executable = "nake"
23
+ s.require_paths = ["lib"]
24
+
25
+ # Ruby version
26
+ s.required_ruby_version = ::Gem::Requirement.new("~> 1.9")
27
+
28
+ # dependencies
29
+ s.add_dependency "term-ansicolor"
30
+
31
+ begin
32
+ require "changelog"
33
+ rescue LoadError
34
+ warn "You have to have changelog gem installed for post install message"
35
+ else
36
+ changelog = CHANGELOG.new(File.join(File.dirname(__FILE__), "CHANGELOG"))
37
+ s.post_install_message = "=== Changes in the last Nake ===\n - #{changelog.last_version_changes.join("\n- ")}"
38
+ end
39
+
40
+ # RubyForge
41
+ s.rubyforge_project = "nake"
42
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ # You might think this is a terrible mess and guess what, you're
5
+ # right mate! However say thanks to authors of RubyGems, not me.
6
+ eval(File.read("nake.gemspec")).tap do |specification|
7
+ specification.version = "#{Nake::VERSION}.pre"
8
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+ require "nake/argv"
5
+
6
+ describe Nake::ArgvParsingMixin do
7
+ def parse(*args)
8
+ args.extend(Nake::ArgvParsingMixin)
9
+ args.extract!
10
+ end
11
+
12
+ describe "#parse!" do
13
+ it "should returns Hash" do
14
+ parse.should be_kind_of(Hash)
15
+ end
16
+
17
+ it "should parse --git-repository to {git_repository: true}" do
18
+ options = parse("--git-repository")
19
+ options[:git_repository].should be_true
20
+ end
21
+
22
+ it "should parse --no-github to {github: false}" do
23
+ options = parse("--no-github")
24
+ options[:github].should be_false
25
+ end
26
+
27
+ it "should parse --controller=posts to {controller: 'posts'}" do
28
+ options = parse("--controller=posts")
29
+ options[:controller].should eql("posts")
30
+ end
31
+
32
+ it "should parse --models=post,comment to {models: ['post', 'comment']}" do
33
+ options = parse("--models=post,comment")
34
+ options[:models].should eql(["post", "comment"])
35
+ end
36
+
37
+ it "should remove argument from ARGV if the argument was successfuly mapped to an option" do
38
+ args = ["--user=botanicus"]
39
+ args.extend(Nake::ArgvParsingMixin)
40
+ args.extract!
41
+ args.should be_empty
42
+ end
43
+
44
+ it "should not remove argument from ARGV if the argument wasn't mapped to an option" do
45
+ args = ["one", "two", "three"]
46
+ args.extend(Nake::ArgvParsingMixin)
47
+ args.extract!
48
+ args.length.should eql(3)
49
+ end
50
+ end
51
+ end
File without changes
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+ require "nake/dsl"
5
+
6
+ describe "Object#task" do
7
+ before(:each) do
8
+ Nake::Task.tasks.clear
9
+ end
10
+
11
+ it "should take name as a first argument" do
12
+ task(:name).name.should eql(:name)
13
+ end
14
+
15
+ it "should optinally take other arguments as a dependencies" do
16
+ task(:release, :build, :tag).dependencies.should eql([:build, :tag])
17
+ end
18
+
19
+ it "should optinally take a block as a task definition" do
20
+ task = task(:release) { "released!" }
21
+ task.should have(1).blocks
22
+ end
23
+
24
+ it "should be able to add a dependencies to the task definition" do
25
+ task(:release, :build)
26
+ task(:release, :tag)
27
+ task(:release).dependencies.should eql([:build, :tag])
28
+ end
29
+
30
+ it "should be able to add a block to the task definition" do
31
+ task = task(:release) { "first block" }
32
+ task(:release) { "second block" }
33
+ -> { task(:release) { "released!" } }.should change { task.blocks.length }.by(1)
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+ require "nake/helpers"
5
+
6
+ describe Nake::TaskHelpers do
7
+ include Nake::TaskHelpers
8
+ describe "#sh" do
9
+ it "should be able to execute external commands"
10
+ it "should show which command runs"
11
+ it "should show STDOUT of the command"
12
+ it "should show STDERR of the command"
13
+ end
14
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+ require "nake/task"
5
+
6
+ describe Nake::Task do
7
+ before(:each) do
8
+ Nake::Task.tasks.clear
9
+ end
10
+
11
+ describe "[]" do
12
+ it "should find task with given name if the name is a symbol"
13
+ it "should find task with given name if the name is a string"
14
+ it "should find task with given alias if the alias is a symbol"
15
+ it "should find task with given alias if the alias is a string"
16
+ end
17
+
18
+ describe "[]=" do
19
+ it "should add the task into the Task.tasks hash with stringified key"
20
+ end
21
+
22
+ describe ".tasks" do
23
+ end
24
+
25
+ describe ".new" do
26
+ it "should returns already existing task object if this object exists" do
27
+ task = Task.new(:release)
28
+ Task.new(:release).object_id.should eql(task.object_id)
29
+ end
30
+ end
31
+
32
+ it "should take name as a first argument" do
33
+ Task.new("name").name.should eql(:name)
34
+ end
35
+
36
+ it "should take name as a first argument" do
37
+ Task.new(:name).name.should eql(:name)
38
+ end
39
+
40
+ describe "#define" do
41
+ it "should puts block into the task.blocks collection" do
42
+ task = Task.new(:name)
43
+ -> { task.define { "a block" } }.should change { task.blocks.length }.by(1)
44
+ end
45
+ end
46
+
47
+ describe "#hidden?" do
48
+ it "should not be hidden by default" do
49
+ task = Task.new(:name)
50
+ task.should_not be_hidden
51
+ end
52
+
53
+ it "should be true if the task is hidden" do
54
+ Task.new(:name).tap do |task|
55
+ task.hidden = true
56
+ task.should be_hidden
57
+ end
58
+ end
59
+
60
+ it "should be false if the task isn't hidden" do
61
+ Task.new(:name).tap do |task|
62
+ task.hidden = false
63
+ task.should_not be_hidden
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#call" do
69
+ it "should call all dependencies"
70
+ it "should call all blocks of the given task"
71
+ end
72
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../spec_helper"
4
+
5
+ load "nake/tasks.rb"
6
+ @result = STDOUT.capture { Task["-T"].call }
7
+
8
+ describe "Default tasks" do
9
+ describe "-H" do
10
+ before(:each) do
11
+ load "nake/tasks.rb"
12
+ end
13
+
14
+ it "should be available as a -H or --help" do
15
+ Task["-H"].should eql(Task["--help"])
16
+ end
17
+
18
+ it "should print a message about using -T and exit" do
19
+ -> { Task["-H"].call }.should raise_error(SystemExit, /-T/)
20
+ end
21
+ end
22
+
23
+ describe "-T" do
24
+ before(:each) do
25
+ load "nake/tasks.rb"
26
+ task(:release, :build, :tag)
27
+ @result = STDOUT.capture { Task["-T"].call }
28
+ end
29
+
30
+ it "should list all available tasks" do
31
+ @result.should match("release")
32
+ end
33
+
34
+ it "should show description if there is any"
35
+
36
+ it "should list dependencies if some are available"
37
+
38
+ it "should list aliases"
39
+
40
+ it "should not show hidden tasks" do
41
+ @result.should_not match("-H")
42
+ end
43
+ end
44
+
45
+ describe "-i" do
46
+ # TODO
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "spec_helper"
4
+ require "nake"
5
+
6
+ describe Nake do
7
+ describe ".run" do
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require "spec"
5
+ rescue LoadError
6
+ abort "You have to install rspec gem!"
7
+ end
8
+
9
+ require "stringio"
10
+
11
+ def STDOUT.capture(&block)
12
+ before = self
13
+ $stdout = StringIO.new
14
+ block.call
15
+ $stdout.rewind
16
+ output = $stdout.read
17
+ $stdout = before
18
+ output
19
+ end
@@ -0,0 +1,12 @@
1
+ #!./bin/nake
2
+ # encoding: utf-8
3
+
4
+ task(:build) do
5
+ sh "gem build nake.gemspec"
6
+ end
7
+
8
+ # ./tasks.rb spec/nake/argv_spec.rb spec/nake/task_spec.rb
9
+ task(:spec) do |*paths, options|
10
+ paths.push("spec") if paths.empty?
11
+ exec "spec #{paths.join(" ")}"
12
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ date: 2009-12-26 00:00:00 +00:00
12
+ default_executable: nake
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: term-ansicolor
16
+ type: :runtime
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: ""
25
+ email: knava.bestvinensis@gmail.com
26
+ executables:
27
+ - nake
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - bin/nake
34
+ - CHANGELOG
35
+ - examples/args.rb
36
+ - examples/basic.rb
37
+ - examples/complex.rb
38
+ - examples/default.rb
39
+ - examples/default_proc.rb
40
+ - examples/dependencies.rb
41
+ - examples/helpers.rb
42
+ - examples/invoking.rb
43
+ - examples/options.rb
44
+ - examples/script.rb
45
+ - lib/nake/argv.rb
46
+ - lib/nake/colors.rb
47
+ - lib/nake/dsl.rb
48
+ - lib/nake/helpers.rb
49
+ - lib/nake/task.rb
50
+ - lib/nake/tasks.rb
51
+ - lib/nake.rb
52
+ - LICENSE
53
+ - nake-0.0.1.gem
54
+ - nake.gemspec
55
+ - nake.pre.gemspec
56
+ - README.textile
57
+ - spec/nake/argv_spec.rb
58
+ - spec/nake/colors_spec.rb
59
+ - spec/nake/dsl_spec.rb
60
+ - spec/nake/helpers_spec.rb
61
+ - spec/nake/task_spec.rb
62
+ - spec/nake/tasks_spec.rb
63
+ - spec/nake_spec.rb
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ - tasks.rb
67
+ - TODO.txt
68
+ has_rdoc: true
69
+ homepage: http://github.com/botanicus/nake
70
+ licenses: []
71
+
72
+ post_install_message: |-
73
+ === Changes in the last Nake ===
74
+ - bin/nake executable
75
+ - sh helper (nake/helpers)
76
+ - task helper (nake/dsl)
77
+ - Task with description, dependencies and blocks
78
+ - Hidden tasks
79
+ - Each task can has multiple aliases
80
+ - Command line arguments parsing. Arguments will be passed as an arguments for blocks of the given task and options will be extracted into a hash, parsed into Ruby data types and passed as the last argument for the blocks.
81
+ - Default tasks for help (-H, --help), list of available tasks (-T, --tasks) and interactive session (-i, --interactive)
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: "1.9"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project: nake
101
+ rubygems_version: 1.3.5
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Nake is light-weight and highly flexible Rake replacement with much better arguments parsing
105
+ test_files: []
106
+