Module: Runfile
- Includes:
- Colsole
- Defined in:
- lib/runfile/dsl.rb,
lib/runfile/util.rb,
lib/runfile/action.rb,
lib/runfile/runner.rb,
lib/runfile/version.rb,
lib/runfile/docopt_helper.rb,
lib/runfile/runfile_helper.rb
Overview
This file defines all the commands supported in a Runfile. All commands are immediately handed over to the Runner instance for handling.
Defined Under Namespace
Classes: Action, DocoptHelper, RunfileHelper, Runner
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Method Summary collapse
-
#action(name, &block) ⇒ Object
Define the action.
-
#call(command_string) ⇒ Object
Cross-call another action.
-
#command(name = nil) ⇒ Object
(also: #endcommand)
Define a new command namespace.
-
#d(obj) ⇒ Object
Debug print and exit.
-
#find_all_in_path(pattern, include_cwd = true) ⇒ Object
Find all files matching a pattern in any of the path directories.
-
#find_in_path(file) ⇒ Object
Find a single file in any of the path directories.
-
#help(text) ⇒ Object
Set the help message for the next action.
-
#name(name) ⇒ Object
Set the name of your Runfile program.
-
#option(flag, text) ⇒ Object
Add an option/flag to the next action (can be called multiple times).
-
#summary(text) ⇒ Object
Set the one line summary of your Runfile program.
-
#usage(text) ⇒ Object
Set the usage pattern for the next action.
-
#version(ver) ⇒ Object
Set the version of your Runfile program.
Instance Method Details
#action(name, &block) ⇒ Object
Define the action
38 39 40 |
# File 'lib/runfile/dsl.rb', line 38 def action(name, &block) Runner.instance.add_action name, &block end |
#call(command_string) ⇒ Object
Cross-call another action
48 49 50 |
# File 'lib/runfile/dsl.rb', line 48 def call(command_string) Runner.instance.cross_call command_string end |
#command(name = nil) ⇒ Object Also known as: endcommand
Define a new command namespace
43 44 45 |
# File 'lib/runfile/dsl.rb', line 43 def command(name=nil) Runner.instance.namespace = name end |
#d(obj) ⇒ Object
Debug print and exit
4 5 6 7 |
# File 'lib/runfile/util.rb', line 4 def d(obj) p obj exit end |
#find_all_in_path(pattern, include_cwd = true) ⇒ Object
Find all files matching a pattern in any of the path directories
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/runfile/util.rb', line 19 def find_all_in_path(pattern, include_cwd=true) result = [] dirs = ENV['PATH'].split(File::PATH_SEPARATOR) dirs.insert(0, Dir.pwd) if include_cwd dirs.each do |d| found = Dir[File.join(d, pattern)] result << found unless found.empty? end return result.empty? ? false : result.flatten.uniq end |
#find_in_path(file) ⇒ Object
Find a single file in any of the path directories
10 11 12 13 14 15 16 |
# File 'lib/runfile/util.rb', line 10 def find_in_path(file) ENV['PATH'].split(File::PATH_SEPARATOR).any? do |d| candidate = File.join(d, file) return candidate if File.exist? candidate end false end |
#help(text) ⇒ Object
Set the help message for the next action
27 28 29 |
# File 'lib/runfile/dsl.rb', line 27 def help(text) Runner.instance.last_help = text end |
#name(name) ⇒ Object
Set the name of your Runfile program
7 8 9 |
# File 'lib/runfile/dsl.rb', line 7 def name(name) Runner.instance.name = name end |
#option(flag, text) ⇒ Object
Add an option/flag to the next action (can be called multiple times)
33 34 35 |
# File 'lib/runfile/dsl.rb', line 33 def option(flag, text) Runner.instance.add_option flag, text end |
#summary(text) ⇒ Object
Set the one line summary of your Runfile program
17 18 19 |
# File 'lib/runfile/dsl.rb', line 17 def summary(text) Runner.instance.summary = text end |