runfile 0.2.7 → 0.2.8
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 +0 -1
- data/lib/runfile.rb +2 -1
- data/lib/runfile/{docopt_maker.rb → docopt_helper.rb} +16 -4
- data/lib/runfile/runfile_helper.rb +82 -0
- data/lib/runfile/runner.rb +15 -60
- data/lib/runfile/templates/Runfile +11 -6
- data/lib/runfile/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df6dc7a19fa65337447fc31211bca292dfe4f51
|
4
|
+
data.tar.gz: b18d49b824c571c79b33bdfce4de8d623341f24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98946aa178216ee977540b219285e7adf68afdb5bf73ae36ad1f1af422e1129be2255ebee3eb1f5155021c84354ddd127031facee9b66e89f875ca11f39d7896
|
7
|
+
data.tar.gz: 53eb5cdc444911e1587490f042381d5b1e0c3d4153fa4b97b8d8b301008ec58fab05a14b6e28e2bb59e1e41644e9efd8dcbbbdc9202c836f0c04835cef12b251
|
data/README.md
CHANGED
data/lib/runfile.rb
CHANGED
@@ -4,9 +4,15 @@ require 'colsole'
|
|
4
4
|
module Runfile
|
5
5
|
include Colsole
|
6
6
|
|
7
|
-
# The
|
8
|
-
# document
|
9
|
-
|
7
|
+
# The DocoptHelper class handles the dynamic generation of the
|
8
|
+
# docopt document and the docopt part of the execution (meaning,
|
9
|
+
# to call Docopt so it returns the parsed arguments or halts with
|
10
|
+
# usage message).
|
11
|
+
class DocoptHelper
|
12
|
+
|
13
|
+
# The constructor expects to get all the textual details
|
14
|
+
# needed to generate a docopt document (name, version,
|
15
|
+
# summary, options) and an array of Action objects.
|
10
16
|
def initialize(name, version, summary, actions, options)
|
11
17
|
@name = name
|
12
18
|
@version = version
|
@@ -17,7 +23,7 @@ module Runfile
|
|
17
23
|
|
18
24
|
# Generate a document based on all the actions, help messages
|
19
25
|
# and options we have collected from the Runfile DSL.
|
20
|
-
def
|
26
|
+
def docopt
|
21
27
|
width, height = detect_terminal_size
|
22
28
|
doc = "#{@name} #{@version}\n"
|
23
29
|
doc += "#{@summary} \n" if @summary
|
@@ -45,5 +51,11 @@ module Runfile
|
|
45
51
|
end
|
46
52
|
doc
|
47
53
|
end
|
54
|
+
|
55
|
+
# Calls the docopt handler, which will either return a parsed
|
56
|
+
# arguments list, or halt execution and show usage.
|
57
|
+
def args(argv)
|
58
|
+
Docopt::docopt(docopt, version: @version, argv:argv)
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'docopt'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module Runfile
|
5
|
+
|
6
|
+
# The RunfileHelper class assists in:
|
7
|
+
# 1. Finding named.runfiles
|
8
|
+
# 2. Creating new runfiles (`run make`)
|
9
|
+
# 3. Showing a list of found system runfiles in a colorful help
|
10
|
+
class RunfileHelper
|
11
|
+
|
12
|
+
# Handle the case when `run` is called without a Runfile
|
13
|
+
# present. We will let the user know they can type `run make`
|
14
|
+
# to create a new sample Runfile.
|
15
|
+
# If the first argument matches the name of a *.runfile name,
|
16
|
+
# we will return it to the caller. Otherwise, we return false
|
17
|
+
# to indicate "no further handling is needed".
|
18
|
+
def handle(argv)
|
19
|
+
# make a new runfile
|
20
|
+
if argv[0] == "make"
|
21
|
+
make_runfile argv[1]
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
# get a list of *.runfile path-wide
|
26
|
+
runfiles = find_runfiles || []
|
27
|
+
|
28
|
+
# if first arg is a valid *.runfile, run it
|
29
|
+
if argv[0]
|
30
|
+
runfile = runfiles.select { |f| f[/#{argv[0]}.runfile/] }.first
|
31
|
+
runfile and return runfile
|
32
|
+
end
|
33
|
+
|
34
|
+
# if we are here, offer some help and advice
|
35
|
+
show_make_help runfiles
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Create a new runfile in the current directory. We can either
|
42
|
+
# create a standard 'Runfile' or a 'named.runfile'.
|
43
|
+
def make_runfile(name=nil)
|
44
|
+
name = 'Runfile' if name.nil?
|
45
|
+
template = File.expand_path("../templates/Runfile", __FILE__)
|
46
|
+
name += ".runfile" unless name == 'Runfile'
|
47
|
+
dest = "#{Dir.pwd}/#{name}"
|
48
|
+
begin
|
49
|
+
File.write(dest, File.read(template))
|
50
|
+
puts "#{name} created."
|
51
|
+
rescue => e
|
52
|
+
abort "Failed creating #{name}\n#{e.message}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Find all *.runfiles path-wide
|
57
|
+
def find_runfiles
|
58
|
+
find_all_in_path '*.runfile'
|
59
|
+
end
|
60
|
+
|
61
|
+
# Show some helpful tips, and a list of available runfiles
|
62
|
+
def show_make_help(runfiles)
|
63
|
+
say "!txtpur!Runfile engine v#{Runfile::VERSION}"
|
64
|
+
runfiles.size < 5 and say "\nTip: Type '!txtblu!run make!txtrst!' or '!txtblu!run make name!txtrst!' to create a runfile.\n Place !txtblu!named.runfiles!txtrst! anywhere in the PATH for global access."
|
65
|
+
if runfiles.empty?
|
66
|
+
say "\n!txtred!Runfile not found."
|
67
|
+
else
|
68
|
+
say ""
|
69
|
+
max = runfiles.max_by(&:length).size
|
70
|
+
width, height = detect_terminal_size
|
71
|
+
runfiles.each do |f|
|
72
|
+
f[/([^\/]+).runfile$/]
|
73
|
+
command = "run #{$1}"
|
74
|
+
spacer_size = width - max - command.size - 6
|
75
|
+
spacer_size = [1, spacer_size].max
|
76
|
+
spacer = '.' * spacer_size
|
77
|
+
say " !txtgrn!#{command}!txtrst! #{spacer} #{f}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/runfile/runner.rb
CHANGED
@@ -4,7 +4,10 @@ require 'pp'
|
|
4
4
|
module Runfile
|
5
5
|
|
6
6
|
# The Runner class is the main workhorse behind Runfile.
|
7
|
-
# It handles all the Runfile DSL commands and executes the
|
7
|
+
# It handles all the Runfile DSL commands and executes the
|
8
|
+
# Runfile with the help of two more specialized classes:
|
9
|
+
# 1. DocoptHelper - for deeper docopt related actions
|
10
|
+
# 2. RunfileHelper - for Runfile creation and system wide search
|
8
11
|
class Runner
|
9
12
|
attr_accessor :last_usage, :last_help, :name, :version,
|
10
13
|
:summary, :namespace, :superspace
|
@@ -89,18 +92,13 @@ module Runfile
|
|
89
92
|
|
90
93
|
private
|
91
94
|
|
92
|
-
# Dynamically generate the docopt document.
|
93
|
-
def docopt
|
94
|
-
maker = DocoptMaker.new(@name, @version, @summary, @actions, @options)
|
95
|
-
maker.make
|
96
|
-
end
|
97
|
-
|
98
95
|
# Call the docopt parser and execute the action with the
|
99
96
|
# parsed arguments.
|
100
97
|
# This should always be called in a begin...rescue block and
|
101
98
|
# you should handle the Docopt::Exit exception.
|
102
99
|
def docopt_exec(argv)
|
103
|
-
|
100
|
+
helper = DocoptHelper.new(@name, @version, @summary, @actions, @options)
|
101
|
+
args = helper.args argv
|
104
102
|
action = find_action argv
|
105
103
|
action or abort "Runfile error: Action not found"
|
106
104
|
@actions[action].execute args
|
@@ -121,61 +119,18 @@ module Runfile
|
|
121
119
|
return false
|
122
120
|
end
|
123
121
|
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# we will execute it.
|
122
|
+
# When `run` is called without a Runfile (or runfile not
|
123
|
+
# found), hand over handling to the RunfileHelper class.
|
124
|
+
# If will either return false if no further handling is needed
|
125
|
+
# on our part, or the name of a runfile to execute.
|
129
126
|
def handle_no_runfile(argv)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
146
|
-
end
|
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})"
|
127
|
+
maker = RunfileHelper.new
|
128
|
+
runfile = maker.handle argv
|
129
|
+
if runfile
|
130
|
+
@superspace = argv[0]
|
131
|
+
execute argv, runfile
|
155
132
|
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"
|
157
133
|
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'
|
179
134
|
end
|
180
135
|
end
|
181
136
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
-
|
1
|
+
name "Greeter"
|
2
|
+
summary "A sample Runfile"
|
2
3
|
version "0.1.0"
|
3
4
|
|
4
|
-
usage "
|
5
|
-
help "
|
6
|
-
option "-
|
7
|
-
action :
|
8
|
-
|
5
|
+
usage "hello [<name> --color]"
|
6
|
+
help "Say hello"
|
7
|
+
option "-c --color", "Greet with color"
|
8
|
+
action :hello do |args|
|
9
|
+
if args['--color']
|
10
|
+
say "!txtgrn!Hello #{args['<name>']}"
|
11
|
+
else
|
12
|
+
say "Hello #{args['<name>']}"
|
13
|
+
end
|
9
14
|
end
|
data/lib/runfile/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.8
|
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: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -49,8 +49,9 @@ files:
|
|
49
49
|
- bin/run
|
50
50
|
- lib/runfile.rb
|
51
51
|
- lib/runfile/action.rb
|
52
|
-
- lib/runfile/
|
52
|
+
- lib/runfile/docopt_helper.rb
|
53
53
|
- lib/runfile/dsl.rb
|
54
|
+
- lib/runfile/runfile_helper.rb
|
54
55
|
- lib/runfile/runner.rb
|
55
56
|
- lib/runfile/templates/Runfile
|
56
57
|
- lib/runfile/util.rb
|