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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4214f82d6684139a8037647c5ccbc573faf47ab4
4
- data.tar.gz: d38adc9cad47620f82812bbe0fe1881e9e2efff8
3
+ metadata.gz: ea9b733a42bb98660d63972f6058640c7066d0ab
4
+ data.tar.gz: ffd28023ce207978725d0fb738d044df06c22149
5
5
  SHA512:
6
- metadata.gz: cf2f7fafb7d05a4ad9888ca22d4f3a507811749fe383b1c579ab0057c26e931331a88c1a88809c4ad3cadf07d658e1ca74006e2cdd9f24ff1ea9113f619f0183
7
- data.tar.gz: bda2f4546fd50cd8550dacf75acf184be4bb580fccc95ca26f8bb778d5fb55c83a17148776059a6dc3a99771b05afc4b55d48f01146366775f1567ce5bd644fc
6
+ metadata.gz: 25f6f6d32f4ca26cb516485520b0d2f193c076fa489c619f223861771cb4cfd5e50bf8a0be29e036fe1c53214850059b7ef980f05c8c1e4adf645025f6061c41
7
+ data.tar.gz: d9a5be0f3a2aa31767265d27d35c787b66e46187586c50405e48acc15dbef2283bad0da83e576f15b3cf8c78cc0ef8ece490ee3e785f9dd6e4a912d10426e09d
data/README.md CHANGED
@@ -72,7 +72,7 @@ Options:
72
72
 
73
73
  ## Test
74
74
 
75
- $ rake test
75
+ $ rake test
76
76
 
77
77
 
78
78
  ## Todo
data/bin/run CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'runfile'
4
+
5
+ # for dev
6
+ # require File.dirname(__FILE__) + "/../lib/runfile"
7
+
4
8
  include Runfile
5
9
 
6
10
  Runner.instance.execute ARGV
data/lib/runfile.rb CHANGED
@@ -4,3 +4,4 @@ require 'runfile/docopt_maker'
4
4
  require 'runfile/action'
5
5
  require 'runfile/runner'
6
6
  require 'runfile/dsl'
7
+ require 'runfile/util'
@@ -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 = "Runfile #{@version}\n"
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
@@ -3,6 +3,11 @@
3
3
  # for handling.
4
4
 
5
5
  module Runfile
6
+ # Set the name of your Runfile program
7
+ def name(name)
8
+ Runner.instance.name = name
9
+ end
10
+
6
11
  # Set the version of your Runfile program
7
12
  def version(ver)
8
13
  Runner.instance.version = ver
@@ -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, :version, :summary, :namespace, :superspace
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
- @last_usage = nil # dsl: usage
16
- @last_help = nil # dsl: help
17
- @superspace = nil # used when filename != Runfile
18
- @namespace = nil # dsl: #command
19
- @actions = {} # dsl: action
20
- @options = {} # dsl: option
21
- @version = "0.0.0" # dsl: version
22
- @summary = false # dsl: summary
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? filename or handle_no_runfile argv
35
+ File.file?(filename) or handle_no_runfile argv
34
36
  begin
35
37
  load filename
36
- rescue
37
- abort "Failed loading file '#{filename}'.\nIs it a valid Runfile?"
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
- sample = File.dirname(__FILE__) + "/../../examples/template/Runfile"
130
- dest = Dir.pwd + "/Runfile"
131
- File.write(dest, File.read(sample))
132
- abort "Runfile created."
133
- elsif argv[0] and File.exist? "#{argv[0]}.runfile"
134
- @superspace = argv[0]
135
- execute argv, "#{argv[0]}.runfile"
136
- else
137
- runfiles = Dir['*.runfile']
138
- runfiles.empty? and abort "Runfile engine v#{Runfile::VERSION}\n\nRunfile not found.\nUse 'run make' to create one."
139
- runfiles.each do |f|
140
- f.slice! '.runfile'
141
- puts "Did you mean 'run #{f}'"
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
@@ -0,0 +1,9 @@
1
+ summary "Application description"
2
+ version "0.1.0"
3
+
4
+ usage "command <arg> [--flag]"
5
+ help "Help line for command"
6
+ option "-f --flag", "Help text for option"
7
+ action :command do |args|
8
+ say "Command running..."
9
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.5"
3
3
  end
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.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: