Sha256: 00e7349b95f08c2aecd5ddb256bf8ad0862a4bec6ec54be2723fc5e14b2bca6d

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ./bin/nake --debug

# This example document how you can change different flags
# - specify these flags in shebang
# - use API directly
# - ./examples/flags --verbose
Nake.verbose = false

# Arguments might be considered as a light-weight variant to tasks
# There are two ways how you can use tasks:
# 1) as a filter, just set a variable --debug
# 2) add your own functionality and then use exit
# 3) just set the task which will run afterwards
Nake.args["-H", "--help"] = lambda { Kernel.abort("This is my customized help!") }

task(:tasks) { puts "Available tasks: #{Nake::Task.tasks.keys.join(", ")}" }
Nake.args["-T", "--tasks"] = lambda { |*| Nake.parse[:task].clear.push("tasks") }

argument("--debug", "--no-debug") do |key, value|
  puts "~ Setting #{key} to #{value}"
  Nake.debug = value
end

# ./examples/arguments.rb --report greet
# ./examples/arguments.rb --report wait
task(:greet) { puts "Hey mate!" }
task(:wait)  { sleep(1) }

argument("--report") do |*|
  @before = Time.now
  at_exit do
    task = Nake.parse[:task].first
    time = Time.now - @before
    puts "Running task #{task} took #{time} seconds"
  end
end

# TODO: execution order, argument helper + args passing to the proc

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
nake-0.1.1 examples/arguments.rb
nake-0.1 examples/arguments.rb
nake-0.0.9.5 examples/arguments.rb
nake-0.0.9.4 examples/arguments.rb
nake-0.0.9.3 examples/arguments.rb
nake-0.0.9.2 examples/arguments.rb
nake-0.0.9.pre examples/arguments.rb
do_riak-0.10.1.pre gems/gems/nake-0.0.8/examples/arguments.rb
nake-0.0.8.pre examples/arguments.rb
nake-0.0.8 examples/arguments.rb
nake-0.0.7 examples/arguments.rb
nake-0.0.6 examples/arguments.rb