runfile 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f2c261b8ea63706e7e2d0e35c26bddd8d4fa643
4
- data.tar.gz: 35ed28228462189497ac6f82fed1891b26293e33
3
+ metadata.gz: 93b12b23dbe13c9268f51757ae21b59fc59abec7
4
+ data.tar.gz: 9ccca34c560d656bbb98ceddbf4059a97540a370
5
5
  SHA512:
6
- metadata.gz: dd69d74e823b0819b2b5943d5fbf4ece4138395590995c9e5e9af2ddedb5ec41dd63b8dfb2d04b98d3f5598e3b8bbea7c05cabeefa4da0405e75ca356838ce36
7
- data.tar.gz: f6179c9c0cf846ea705214ce2b1aa003b3cf0e17206368486d8e6486e06066fbfc2ab3204a251186c14cbdb381db559445ea231b6fe63a3c73ebd85a57b0c7b1
6
+ metadata.gz: a8e21b6ef2cdab994ab2e368d5fa1f492f7397868d79faa6825823730fa1ea80aa219c858e09843e8d96f524c000e1ef649abd24de9d4ac6b7e57ae5e4903c10
7
+ data.tar.gz: fe4e88c465ab572016bc331b81b388c743564be4092f16cbe3d5df27de0bf0018b14175b918598dd48dc1b2db13e825b702440854f527c8cdb1984404cfe34e8
data/README.md CHANGED
@@ -7,11 +7,12 @@ Runfile - If Rake and Docopt had a baby
7
7
  [![Dependency Status](https://gemnasium.com/DannyBen/runfile.svg)](https://gemnasium.com/DannyBen/runfile)
8
8
  <!-- [![Gem](https://img.shields.io/gem/dt/runfile.svg)](https://rubygems.org/gems/runfile) -->
9
9
 
10
+ ---
11
+
10
12
  A beautiful command line application framework.
11
13
  Rake-inspired, Docopt inside.
12
14
 
13
-
14
- ## Wait, What? ##
15
+ ---
15
16
 
16
17
  **Runfile** lets you create command line applications in a way similar
17
18
  to [Rake](https://github.com/ruby/rake), but with the full power of
@@ -22,7 +23,7 @@ You create a `Runfile`, and execute commands with
22
23
 
23
24
  [Learn More in the Wiki](https://github.com/DannyBen/runfile/wiki)
24
25
 
25
-
26
+ ---
26
27
 
27
28
  ## Install ##
28
29
 
data/lib/runfile.rb CHANGED
@@ -5,3 +5,5 @@ require 'runfile/action'
5
5
  require 'runfile/runner'
6
6
  require 'runfile/dsl'
7
7
  require 'runfile/util'
8
+
9
+ require 'runfile/extensions/exec'
@@ -0,0 +1,81 @@
1
+ # This module provides methods for easily and politely run shell commands
2
+ # through a Runfile action.
3
+ # It is mainly a convenient wrapper around `system` and `exec` and it also
4
+ # adds functions for running background tasks with ease.
5
+
6
+ module Runfile
7
+ module Exec
8
+ def self.pid_dir=(dir)
9
+ @@pid_dir = dir
10
+ end
11
+
12
+ def self.pid_dir
13
+ @@pid_dir
14
+ end
15
+
16
+ # Run a command, wait until it is done and continue
17
+ def run(cmd)
18
+ cmd = @before_run_block.call(cmd) if @before_run_block
19
+ return false unless cmd
20
+ say "!txtgrn!> #{cmd}"
21
+ system cmd
22
+ @after_run_block.call(cmd) if @after_run_block
23
+ end
24
+
25
+ # Run a command, wait until it is done, then exit
26
+ def run!(cmd)
27
+ cmd = @before_run_block.call(cmd) if @before_run_block
28
+ return false unless cmd
29
+ say "!txtgrn!> #{cmd}"
30
+ exec cmd
31
+ end
32
+
33
+ # Run a command in the background, optionally log to a log file and save
34
+ # the process ID in a pid file
35
+ def run_bg(cmd, pid: nil, log: '/dev/null')
36
+ cmd = @before_run_block.call(cmd) if @before_run_block
37
+ return false unless cmd
38
+ full_cmd = "exec #{cmd} >#{log} 2>&1"
39
+ say "!txtgrn!> #{full_cmd}"
40
+ process = IO.popen "exec #{cmd} >#{log} 2>&1"
41
+ File.write pidfile(pid), process.pid if pid
42
+ @after_run_block.call(cmd) if @after_run_block
43
+ return process.pid
44
+ end
45
+
46
+ # Stop a command started with 'run_bg'. Provide the name of he pid file you
47
+ # used in 'run_bg'
48
+ def stop_bg(pid)
49
+ file = pidfile(pid)
50
+ if File.exist? file
51
+ pid = File.read file
52
+ File.delete file
53
+ run "kill -s TERM #{pid}"
54
+ else
55
+ say "!txtred!PID file not found."
56
+ end
57
+ end
58
+
59
+ # Set a block to be called before each run
60
+ def before_run(&block)
61
+ @before_run_block = block
62
+ end
63
+
64
+ # Set a block to be called after each run
65
+ def after_run(&block)
66
+ @after_run_block = block
67
+ end
68
+
69
+ private
70
+
71
+ def pid_dir
72
+ defined?(@@pid_dir) ? @@pid_dir : nil
73
+ end
74
+
75
+ def pidfile(pid)
76
+ pid_dir ? "#{pid_dir}/#{pid}.pid" : "#{pid}.pid"
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -39,33 +39,61 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: runfile-tasks
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.8'
47
+ version: '0.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.8'
54
+ version: '0.4'
55
55
  - !ruby/object:Gem::Dependency
56
- name: run-gem-dev
56
+ name: cucumber
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.2'
61
+ version: '2.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.2'
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-expectations
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
69
97
  description: Build command line applications per project with ease. Rake-inspired,
70
98
  Docopt inside.
71
99
  email: db@dannyben.com
@@ -82,6 +110,7 @@ files:
82
110
  - lib/runfile/action.rb
83
111
  - lib/runfile/docopt_helper.rb
84
112
  - lib/runfile/dsl.rb
113
+ - lib/runfile/extensions/exec.rb
85
114
  - lib/runfile/runfile_helper.rb
86
115
  - lib/runfile/runner.rb
87
116
  - lib/runfile/templates/Runfile
@@ -99,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
128
  requirements:
100
129
  - - ">="
101
130
  - !ruby/object:Gem::Version
102
- version: '0'
131
+ version: 2.0.0
103
132
  required_rubygems_version: !ruby/object:Gem::Requirement
104
133
  requirements:
105
134
  - - ">="