runfile 0.6.2 → 0.6.3

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: fcd488881171918b71a9b0ed134e2b9dbedf4055
4
- data.tar.gz: 5b71cceb782e4a4a6ccd6215d5642a937bfe7da1
3
+ metadata.gz: 07eb84f262b49c776d311056be64345f415c94da
4
+ data.tar.gz: fc740fc871111c1bac8a30df994b4ce4778c1ecf
5
5
  SHA512:
6
- metadata.gz: 27247b748385fd0ae5f76d4a3eccea430ea0eb003ecd825c41c47310147a129a4c37d5d5ecfd03d5404e4dfb4fe2ebcf241766b5ee3dc4b1083ef7a187b7d205
7
- data.tar.gz: 4478310d2e8866423f508a8ba4ac58bf32b91150237d01b718f485556e092b709a77ebd954b9adeb3bd1c4cc4cef8d4b79375247ab14a5dfc5bde3406666d258
6
+ metadata.gz: 57b71aaad3c8bde5c96064abe7ab2662509903f327cbed5f8fb43caa6ffc104f5c0f437ae10f8c51ba71018c23fd5c3eb4b75dd5f05bd8c1a3f658f5fe7e4b44
7
+ data.tar.gz: f04af615efa538afc2f6fefe69aa65815ab87069e4281a446694d99e57d5dc966b7cf9da094c69699bdce77f28b504216d81ad0cd2dcaa4c290fa99f37802d42
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  Runfile - If Rake and Docopt had a baby
2
2
  ==================================================
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/runfile.svg)](http://badge.fury.io/rb/runfile)
5
- [![Build Status](https://travis-ci.org/DannyBen/runfile.svg?branch=master)](https://travis-ci.org/DannyBen/runfile)
6
- [![Code Climate](https://codeclimate.com/github/DannyBen/runfile/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/runfile)
7
- [![Dependency Status](https://gemnasium.com/DannyBen/runfile.svg)](https://gemnasium.com/DannyBen/runfile)
8
- <!-- [![Gem](https://img.shields.io/gem/dt/runfile.svg)](https://rubygems.org/gems/runfile) -->
4
+ [![Gem](https://img.shields.io/gem/v/runfile.svg?style=flat-square)](https://rubygems.org/gems/runfile)
5
+ [![Travis](https://img.shields.io/travis/DannyBen/runfile.svg?style=flat-square)](https://travis-ci.org/DannyBen/runfile)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/runfile.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/runfile)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/runfile.svg?style=flat-square)](https://gemnasium.com/DannyBen/runfile)
8
+ [![Gem](https://img.shields.io/gem/dt/runfile.svg?style=flat-square)](https://rubygems.org/gems/runfile)
9
9
 
10
10
  ---
11
11
 
data/lib/runfile.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'runfile/version'
2
+ require 'runfile/settings'
2
3
  require 'runfile/docopt_helper'
3
4
  require 'runfile/runfile_helper'
4
5
  require 'runfile/action'
5
6
  require 'runfile/runner'
6
7
  require 'runfile/dsl'
7
8
  require 'runfile/util'
8
- require 'runfile/settings'
9
9
 
10
10
  require 'runfile/extensions/exec'
@@ -29,7 +29,7 @@ module Runfile
29
29
  # Generate a document based on all the actions, help messages
30
30
  # and options we have collected from the Runfile DSL.
31
31
  def docopt
32
- width, height = detect_terminal_size
32
+ width = detect_terminal_size[0]
33
33
  doc = []
34
34
  doc << (@version ? "#{@name} #{@version}" : "#{@name}")
35
35
  doc << "#{@summary}" if @summary
@@ -8,6 +8,7 @@ module Runfile
8
8
  # 2. Creating new runfiles (`run make`)
9
9
  # 3. Showing a list of found system runfiles in a colorful help
10
10
  class RunfileHelper
11
+ include SettingsMixin
11
12
 
12
13
  # Handle the case when `run` is called without a Runfile
13
14
  # present. We will let the user know they can type `run make`
@@ -79,7 +80,7 @@ module Runfile
79
80
  say "\n!txtred!Runfile not found."
80
81
  else
81
82
  say ""
82
- say_runfile_list runfiles, compact
83
+ compact ? say_runfile_usage(runfiles) : say_runfile_list(runfiles)
83
84
  end
84
85
  end
85
86
 
@@ -106,26 +107,30 @@ module Runfile
106
107
  end
107
108
 
108
109
  # Output the list of available runfiles
109
- def say_runfile_list(runfiles, compact=false)
110
+ def say_runfile_list(runfiles)
110
111
  runfile_paths = runfiles.map { |f| File.dirname f }
111
112
  max = runfile_paths.max_by(&:length).size
112
113
  width, height = detect_terminal_size
113
114
  runfiles.each do |f|
114
115
  f[/([^\/]+).runfile$/]
115
116
  command = "run #{$1}"
116
- if compact
117
- say " !txtgrn!#{command}!txtrst!"
118
- else
119
- spacer_size = width - max - command.size - 6
120
- spacer_size = [1, spacer_size].max
121
- spacer = '.' * spacer_size
122
- say " !txtgrn!#{command}!txtrst! #{spacer} #{File.dirname f}"
123
- end
117
+ spacer_size = width - max - command.size - 6
118
+ spacer_size = [1, spacer_size].max
119
+ spacer = '.' * spacer_size
120
+ say " !txtgrn!#{command}!txtrst! #{spacer} #{File.dirname f}"
124
121
  end
125
122
  end
126
123
 
127
- def settings
128
- @settings ||= Settings.new.as_struct
124
+ # Output the list of available runfiles without filename
125
+ def say_runfile_usage(runfiles)
126
+ namelist = runfiles.map {|f| /([^\/]+).runfile$/.match(f)[1] }
127
+ width = detect_terminal_size[0]
128
+ max = namelist.max_by(&:length).length
129
+ message = " " + namelist.map {|f| f.ljust max+1 }.join(' ')
130
+
131
+ say "#{settings.intro}\n" if settings.intro
132
+ say "Usage: run <file>"
133
+ say word_wrap(message, width)
129
134
  end
130
135
 
131
136
  end
@@ -1,5 +1,5 @@
1
+ require 'singleton'
1
2
  require 'docopt'
2
- require 'pp'
3
3
 
4
4
  module Runfile
5
5
 
@@ -9,11 +9,12 @@ module Runfile
9
9
  # 1. DocoptHelper - for deeper docopt related actions
10
10
  # 2. RunfileHelper - for Runfile creation and system wide search
11
11
  class Runner
12
+ include Singleton
13
+ include SettingsMixin
14
+
12
15
  attr_accessor :last_usage, :last_help, :name, :version,
13
16
  :summary, :namespace, :superspace
14
17
 
15
- @@instance = nil
16
-
17
18
  # Initialize all variables to sensible defaults.
18
19
  def initialize
19
20
  @superspace = nil # used when filename != Runfile
@@ -28,21 +29,17 @@ module Runfile
28
29
  @summary = false # dsl: summary
29
30
  end
30
31
 
31
- # Return a singleton Runner instance.
32
- def self.instance
33
- @@instance ||= self.new
34
- end
35
-
36
32
  # Load and execute a Runfile call.
37
33
  def execute(argv, filename='Runfile')
38
34
  @ignore_settings = !filename
39
35
  filename and File.file?(filename) or handle_no_runfile argv
40
36
  begin
37
+ load settings.helper if settings.helper
41
38
  load filename
42
39
  rescue => ex
43
40
  abort "Runfile error:\n#{ex.message}\n#{ex.backtrace[0]}"
44
41
  end
45
- @@instance.run *argv
42
+ run *argv
46
43
  end
47
44
 
48
45
  # Add an action to the @actions array, and use the last known
@@ -6,9 +6,6 @@ module Runfile
6
6
  # The Settings class handles '.runfile' YAML config files.
7
7
  # If found in the current directory, we will use their content.
8
8
  class Settings
9
- def initialize
10
- end
11
-
12
9
  def as_struct
13
10
  OpenStruct.new settings
14
11
  end
@@ -24,4 +21,10 @@ module Runfile
24
21
  end
25
22
  end
26
23
 
24
+ module SettingsMixin
25
+ def settings
26
+ @settings ||= Settings.new.as_struct
27
+ end
28
+ end
29
+
27
30
  end
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
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.6.2
4
+ version: 0.6.3
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-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole