runfile 0.2.2 → 0.2.5
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 +4 -4
- data/README.md +1 -1
- data/bin/run +4 -0
- data/lib/runfile.rb +1 -0
- data/lib/runfile/docopt_maker.rb +3 -2
- data/lib/runfile/dsl.rb +5 -0
- data/lib/runfile/runner.rb +60 -26
- data/lib/runfile/templates/Runfile +9 -0
- data/lib/runfile/util.rb +29 -0
- data/lib/runfile/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9b733a42bb98660d63972f6058640c7066d0ab
|
4
|
+
data.tar.gz: ffd28023ce207978725d0fb738d044df06c22149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f6f6d32f4ca26cb516485520b0d2f193c076fa489c619f223861771cb4cfd5e50bf8a0be29e036fe1c53214850059b7ef980f05c8c1e4adf645025f6061c41
|
7
|
+
data.tar.gz: d9a5be0f3a2aa31767265d27d35c787b66e46187586c50405e48acc15dbef2283bad0da83e576f15b3cf8c78cc0ef8ece490ee3e785f9dd6e4a912d10426e09d
|
data/README.md
CHANGED
data/bin/run
CHANGED
data/lib/runfile.rb
CHANGED
data/lib/runfile/docopt_maker.rb
CHANGED
@@ -7,7 +7,8 @@ module Runfile
|
|
7
7
|
# The DocoptMaker class handles the dynamic generation of the docopt
|
8
8
|
# document.
|
9
9
|
class DocoptMaker
|
10
|
-
def initialize(version, summary, actions, options)
|
10
|
+
def initialize(name, version, summary, actions, options)
|
11
|
+
@name = name
|
11
12
|
@version = version
|
12
13
|
@summary = summary
|
13
14
|
@actions = actions
|
@@ -18,7 +19,7 @@ module Runfile
|
|
18
19
|
# and options we have collected from the Runfile DSL.
|
19
20
|
def make
|
20
21
|
width, height = detect_terminal_size
|
21
|
-
doc = "
|
22
|
+
doc = "#{@name} #{@version}\n"
|
22
23
|
doc += "#{@summary} \n" if @summary
|
23
24
|
doc += "\nUsage:\n";
|
24
25
|
@actions.each do |name, action|
|
data/lib/runfile/dsl.rb
CHANGED
data/lib/runfile/runner.rb
CHANGED
@@ -6,20 +6,22 @@ module Runfile
|
|
6
6
|
# The Runner class is the main workhorse behind Runfile.
|
7
7
|
# It handles all the Runfile DSL commands and executes the Runfile.
|
8
8
|
class Runner
|
9
|
-
attr_accessor :last_usage, :last_help, :
|
9
|
+
attr_accessor :last_usage, :last_help, :name, :version,
|
10
|
+
:summary, :namespace, :superspace
|
10
11
|
|
11
12
|
@@instance = nil
|
12
13
|
|
13
14
|
# Initialize all variables to sensible defaults.
|
14
15
|
def initialize
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@namespace = nil
|
19
|
-
@actions = {}
|
20
|
-
@options = {}
|
21
|
-
@
|
22
|
-
@
|
16
|
+
@superspace = nil # used when filename != Runfile
|
17
|
+
@last_usage = nil # dsl: usage
|
18
|
+
@last_help = nil # dsl: help
|
19
|
+
@namespace = nil # dsl: #command
|
20
|
+
@actions = {} # dsl: action
|
21
|
+
@options = {} # dsl: option
|
22
|
+
@name = "Runfile" # dsl: name
|
23
|
+
@version = "0.0.0" # dsl: version
|
24
|
+
@summary = false # dsl: summary
|
23
25
|
end
|
24
26
|
|
25
27
|
# Return a singleton Runner instance.
|
@@ -30,11 +32,11 @@ module Runfile
|
|
30
32
|
|
31
33
|
# Load and execute a Runfile call.
|
32
34
|
def execute(argv, filename='Runfile')
|
33
|
-
File.file?
|
35
|
+
File.file?(filename) or handle_no_runfile argv
|
34
36
|
begin
|
35
37
|
load filename
|
36
|
-
rescue
|
37
|
-
abort "
|
38
|
+
rescue => e
|
39
|
+
abort "Runfile error:\n#{e.message}"
|
38
40
|
end
|
39
41
|
@@instance.run *argv
|
40
42
|
end
|
@@ -89,7 +91,7 @@ module Runfile
|
|
89
91
|
|
90
92
|
# Dynamically generate the docopt document.
|
91
93
|
def docopt
|
92
|
-
maker = DocoptMaker.new(@version, @summary, @actions, @options)
|
94
|
+
maker = DocoptMaker.new(@name, @version, @summary, @actions, @options)
|
93
95
|
maker.make
|
94
96
|
end
|
95
97
|
|
@@ -125,23 +127,55 @@ module Runfile
|
|
125
127
|
# If the first argument matches the name of a *.runfile name,
|
126
128
|
# we will execute it.
|
127
129
|
def handle_no_runfile(argv)
|
130
|
+
# make a new runfile
|
128
131
|
if argv[0] == "make"
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
runfiles.
|
139
|
-
|
140
|
-
|
141
|
-
|
132
|
+
make_runfile argv[1]
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
|
136
|
+
# get a list of *.runfile path-wide
|
137
|
+
runfiles = find_runfiles || []
|
138
|
+
|
139
|
+
# if first arg is a valid *.runfile, run it
|
140
|
+
if argv[0]
|
141
|
+
runfile = runfiles.select { |f| f[/#{argv[0]}.runfile/] }.first
|
142
|
+
if runfile
|
143
|
+
@superspace = argv[0]
|
144
|
+
execute argv, runfile
|
145
|
+
exit
|
142
146
|
end
|
143
147
|
end
|
148
|
+
|
149
|
+
# if we are here, offer some help and advice
|
150
|
+
say "!txtpur!Runfile engine v#{Runfile::VERSION}\n"
|
151
|
+
runfiles.empty? and say "!txtred!Runfile not found."
|
152
|
+
runfiles.each do |f|
|
153
|
+
f[/([^\/]+).runfile$/]
|
154
|
+
say "Did you mean '!txtgrn!run #{$1}!txtrst!' (#{f})"
|
155
|
+
end
|
156
|
+
say "\nUse '!txtblu!run make!txtrst!' to create 'Runfile'.\nUse '!txtblu!run make name!txtrst!' to create 'name.runfile'.\nPlace named.runfiles anywhere in the path for global access.\n"
|
144
157
|
exit
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
# Create a new runfile in the current directory. We can either
|
162
|
+
# create a standard 'Runfile' or a 'named.runfile'.
|
163
|
+
def make_runfile(name=nil)
|
164
|
+
name = 'Runfile' if name.nil?
|
165
|
+
template = File.expand_path("../templates/Runfile", __FILE__)
|
166
|
+
name += ".runfile" unless name == 'Runfile'
|
167
|
+
dest = "#{Dir.pwd}/#{name}"
|
168
|
+
begin
|
169
|
+
File.write(dest, File.read(template))
|
170
|
+
puts "#{name} created."
|
171
|
+
rescue => e
|
172
|
+
abort "Failed creating #{name}\n#{e.message}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# Find all *.runfiles path-wide
|
177
|
+
def find_runfiles
|
178
|
+
find_all_in_path '*.runfile'
|
145
179
|
end
|
146
180
|
end
|
147
181
|
end
|
data/lib/runfile/util.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Runfile
|
2
|
+
|
3
|
+
# Debug print and exit
|
4
|
+
def d(obj)
|
5
|
+
p obj
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
# Find a single file in any of the path directories
|
10
|
+
def find_in_path(file)
|
11
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |d|
|
12
|
+
candidate = File.join(d, file)
|
13
|
+
return candidate if File.exist? candidate
|
14
|
+
end
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
# Find all files matching a pattern in any of the path directories
|
19
|
+
def find_all_in_path(pattern, include_cwd=true)
|
20
|
+
result = []
|
21
|
+
dirs = ENV['PATH'].split(File::PATH_SEPARATOR)
|
22
|
+
dirs.insert(0, Dir.pwd) if include_cwd
|
23
|
+
dirs.each do |d|
|
24
|
+
found = Dir[File.join(d, pattern)]
|
25
|
+
result << found unless found.empty?
|
26
|
+
end
|
27
|
+
return result.empty? ? false : result.flatten
|
28
|
+
end
|
29
|
+
end
|
data/lib/runfile/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
@@ -52,6 +52,8 @@ files:
|
|
52
52
|
- lib/runfile/docopt_maker.rb
|
53
53
|
- lib/runfile/dsl.rb
|
54
54
|
- lib/runfile/runner.rb
|
55
|
+
- lib/runfile/templates/Runfile
|
56
|
+
- lib/runfile/util.rb
|
55
57
|
- lib/runfile/version.rb
|
56
58
|
homepage: https://github.com/DannyBen/runfile
|
57
59
|
licenses:
|