runfile 0.3.3 → 0.3.4
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 +2 -1
- data/lib/runfile/dsl.rb +3 -2
- data/lib/runfile/runner.rb +18 -12
- data/lib/runfile/util.rb +3 -0
- data/lib/runfile/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11d95123351c1b39b85ab9922f790ca7b0f80efb
|
4
|
+
data.tar.gz: 2bb5759b98df1f2d44c64fe634a4b1ed3ee819e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a9c14a241d455601eba541028858cb29381d3dd5fb833079e3c3d3bb437820fb38421d5082cbd78743f6ff60a90ae548aa186b6e7ff9b8ac4582c518714bdc
|
7
|
+
data.tar.gz: aa5767d460f6f88130ba8eb48987d8e8d5e20eba368b49b52269d676d16c9150f6384c043b3a2f2d82c35eff93d2337d40d298db202058b78fb54fbe04600961
|
data/README.md
CHANGED
@@ -4,7 +4,8 @@ Runfile - If Rake and Docopt had a baby
|
|
4
4
|
[](http://badge.fury.io/rb/runfile)
|
5
5
|
[](https://travis-ci.org/DannyBen/runfile)
|
6
6
|
[](https://codeclimate.com/github/DannyBen/runfile)
|
7
|
-
[](https://gemnasium.com/DannyBen/runfile)
|
8
|
+
<!-- [](https://rubygems.org/gems/runfile) -->
|
8
9
|
|
9
10
|
A beautiful command line application framework.
|
10
11
|
Rake-inspired, Docopt inside.
|
data/lib/runfile/dsl.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# All commands are immediately handed over to the Runner instance
|
3
3
|
# for handling.
|
4
4
|
|
5
|
+
# Smells of :reek:UtilityFunction
|
5
6
|
module Runfile
|
6
7
|
# Set the name of your Runfile program
|
7
8
|
def name(name)
|
@@ -35,8 +36,8 @@ module Runfile
|
|
35
36
|
end
|
36
37
|
|
37
38
|
# Define the action
|
38
|
-
def action(name, &block)
|
39
|
-
Runner.instance.add_action name, &block
|
39
|
+
def action(name, altname=nil, &block)
|
40
|
+
Runner.instance.add_action name, altname, &block
|
40
41
|
end
|
41
42
|
|
42
43
|
# Define a new command namespace
|
data/lib/runfile/runner.rb
CHANGED
@@ -38,16 +38,18 @@ module Runfile
|
|
38
38
|
File.file?(filename) or handle_no_runfile argv
|
39
39
|
begin
|
40
40
|
load filename
|
41
|
-
rescue =>
|
42
|
-
abort "Runfile error:\n#{
|
41
|
+
rescue => ex
|
42
|
+
abort "Runfile error:\n#{ex.message}\n#{ex.backtrace[0]}"
|
43
43
|
end
|
44
44
|
@@instance.run *argv
|
45
45
|
end
|
46
46
|
|
47
47
|
# Add an action to the @actions array, and use the last known
|
48
48
|
# usage and help messages sent by the DSL.
|
49
|
-
def add_action(name, &block)
|
50
|
-
|
49
|
+
def add_action(name, altname=nil, &block)
|
50
|
+
if @last_usage.nil?
|
51
|
+
@last_usage = altname ? "( #{name} | #{altname} )" : name
|
52
|
+
end
|
51
53
|
[@namespace, @superspace].each do |prefix|
|
52
54
|
prefix or next
|
53
55
|
name = "#{prefix}_#{name}"
|
@@ -57,12 +59,16 @@ module Runfile
|
|
57
59
|
@actions[name] = Action.new(block, @last_usage, @last_help)
|
58
60
|
@last_usage = nil
|
59
61
|
@last_help = nil
|
62
|
+
if altname
|
63
|
+
@last_usage = false
|
64
|
+
add_action(altname, nil, &block)
|
65
|
+
end
|
60
66
|
end
|
61
67
|
|
62
68
|
# Add an option flag and its help text.
|
63
69
|
def add_option(flag, text, scope=nil)
|
64
70
|
scope or scope = 'Options'
|
65
|
-
@options[scope]
|
71
|
+
@options[scope] ||= {}
|
66
72
|
@options[scope][flag] = text
|
67
73
|
end
|
68
74
|
|
@@ -72,8 +78,8 @@ module Runfile
|
|
72
78
|
def run(*argv)
|
73
79
|
begin
|
74
80
|
docopt_exec argv
|
75
|
-
rescue Docopt::Exit =>
|
76
|
-
puts
|
81
|
+
rescue Docopt::Exit => ex
|
82
|
+
puts ex.message
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
@@ -84,9 +90,9 @@ module Runfile
|
|
84
90
|
argv = command_string.split /\s(?=(?:[^"]|"[^"]*")*$)/
|
85
91
|
begin
|
86
92
|
docopt_exec argv
|
87
|
-
rescue Docopt::Exit =>
|
93
|
+
rescue Docopt::Exit => ex
|
88
94
|
puts "Cross call failed: #{command_string}"
|
89
|
-
abort
|
95
|
+
abort ex.message
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
@@ -114,9 +120,9 @@ module Runfile
|
|
114
120
|
# assume this is the requested one (since we will not reach
|
115
121
|
# this point unless the usage pattern matches).
|
116
122
|
def find_action(argv)
|
117
|
-
3.downto(1).each do |
|
118
|
-
next unless argv.size >=
|
119
|
-
action = argv[0..
|
123
|
+
3.downto(1).each do |count|
|
124
|
+
next unless argv.size >= count
|
125
|
+
action = argv[0..count-1].join('_').to_sym
|
120
126
|
return action if @actions.has_key? action
|
121
127
|
end
|
122
128
|
return :global if @actions.has_key? :global
|
data/lib/runfile/util.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
# Utility methods
|
1
2
|
module Runfile
|
2
3
|
# Debug print and exit
|
4
|
+
# Smells of :reek:UncommunicativeMethodName
|
3
5
|
def d(obj)
|
4
6
|
pp obj
|
5
7
|
exit
|
6
8
|
end
|
7
9
|
|
8
10
|
# Return an array of path directories
|
11
|
+
# Smells of :reek:UtilityFunction
|
9
12
|
def path_dirs
|
10
13
|
ENV['PATH'].split(File::PATH_SEPARATOR)
|
11
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.3.
|
4
|
+
version: 0.3.4
|
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-
|
11
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|