Module: Runfile

Includes:
Colsole
Defined in:
lib/runfile/dsl.rb,
lib/runfile/exec.rb,
lib/runfile/setup.rb,
lib/runfile/action.rb,
lib/runfile/runner.rb,
lib/runfile/version.rb,
lib/runfile/settings.rb,
lib/runfile/deprecations.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

Modules: Exec, SettingsMixin Classes: Action, DocoptHelper, ExecHandler, RunfileHelper, Runner, Settings

Constant Summary collapse

VERSION =
"0.8.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.pid_dirObject

Set the directory where PID files are stored when using ‘run_bg`

Runfile.pid_dir = 'tmp'


5
6
7
# File 'lib/runfile/setup.rb', line 5

def pid_dir
  @pid_dir
end

.quietObject

Disable echoing of the command when using ‘run` or `run!`

Runfile.quiet = true


9
10
11
# File 'lib/runfile/setup.rb', line 9

def quiet
  @quiet
end

Class Method Details

.setup {|_self| ... } ⇒ Object

You can also configure Runfile by providing a block:

Runfile.setup do |config|
  config.quiet = true
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Runfile)

    the object that the method was called on



15
16
17
# File 'lib/runfile/setup.rb', line 15

def setup
  yield self
end

Instance Method Details

#action(name, altname = nil, &block) ⇒ Object

Define the action

action :server do |args|
  run 'rails server'
end


53
54
55
# File 'lib/runfile/dsl.rb', line 53

def action(name, altname=nil, &block) 
  Runner.instance.add_action name, altname, &block
end

#after_run(&block) ⇒ Object

Set a block to be called after each run

before_run do |command|
  puts "AFTER #{command}"
end


112
113
114
# File 'lib/runfile/dsl.rb', line 112

def after_run(&block)
  ExecHandler.instance.after_run &block
end

#before_run(&block) ⇒ Object

Set a block to be called before each run. The block should return the command to run, since this is intended to let the block modify the command if it needs to.

before_run do |command|
  puts "BEFORE #{command}"
  command
end


104
105
106
# File 'lib/runfile/dsl.rb', line 104

def before_run(&block)
  ExecHandler.instance.before_run &block
end

#command(name = nil) ⇒ Object Also known as: endcommand

Define a new command namespace

command 'server'
# ... define actions here
endcommand


61
62
63
# File 'lib/runfile/dsl.rb', line 61

def command(name=nil)
  Runner.instance.namespace = name
end

#example(text) ⇒ Object

Set an example command (can be called multiple times)

example 'server --background'


45
46
47
# File 'lib/runfile/dsl.rb', line 45

def example(text)
  Runner.instance.add_example text
end

#execute(command_string) ⇒ Object

Cross-call another action

execute 'other_action'


67
68
69
# File 'lib/runfile/dsl.rb', line 67

def execute(command_string)
  Runner.instance.cross_call command_string
end

#help(text) ⇒ Object

Set the help message for the next action

help 'Starts the server in the foreground or background'


32
33
34
# File 'lib/runfile/dsl.rb', line 32

def help(text)
  Runner.instance.last_help = text
end

#name(name) ⇒ Object

Set the name of your Runfile program

name 'My Runfile'


8
9
10
# File 'lib/runfile/dsl.rb', line 8

def name(name)
  Runner.instance.name = name
end

#option(flag, text, scope = nil) ⇒ Object

Add an option/flag to the next action (can be called multiple times)

option '-b --background', 'Start in the background'


39
40
41
# File 'lib/runfile/dsl.rb', line 39

def option(flag, text, scope=nil)
  Runner.instance.add_option flag, text, scope
end

#run(*args) ⇒ Object

Run a command, wait until it is done and continue

run 'rails server'


73
74
75
# File 'lib/runfile/dsl.rb', line 73

def run(*args)
  ExecHandler.instance.run *args
end

#run!(*args) ⇒ Object

Run a command, wait until it is done, then exit

run! 'rails server'


79
80
81
# File 'lib/runfile/dsl.rb', line 79

def run!(*args)
  ExecHandler.instance.run! *args
end

#run_bg(*args) ⇒ Object

Run a command in the background, optionally log to a log file and save the process ID in a pid file

run_bg 'rails server', pid: 'rails', log: 'tmp/log.log'


86
87
88
# File 'lib/runfile/dsl.rb', line 86

def run_bg(*args)
  ExecHandler.instance.run_bg *args
end

#stop_bg(*args) ⇒ Object

Stop a command started with ‘run_bg’. Provide the name of he pid file you used in ‘run_bg’

stop_bg 'rails'


93
94
95
# File 'lib/runfile/dsl.rb', line 93

def stop_bg(*args)
  ExecHandler.instance.stop_bg *args
end

#summary(text) ⇒ Object

Set the one line summary of your Runfile program

summary 'Utilities for my server'


20
21
22
# File 'lib/runfile/dsl.rb', line 20

def summary(text)
  Runner.instance.summary = text
end

#usage(text) ⇒ Object

Set the usage pattern for the next action

usage 'server [--background]'


26
27
28
# File 'lib/runfile/dsl.rb', line 26

def usage(text)
  Runner.instance.last_usage = text
end

#version(ver) ⇒ Object

Set the version of your Runfile program

version '0.1.0'


14
15
16
# File 'lib/runfile/dsl.rb', line 14

def version(ver)
  Runner.instance.version = ver
end