runfile 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b3f76f9bd21810f1bcec6852443b345ed34b96b
4
- data.tar.gz: e0a618c50953691f9c4e8e03d6a07d889406b2c7
3
+ metadata.gz: 11d95123351c1b39b85ab9922f790ca7b0f80efb
4
+ data.tar.gz: 2bb5759b98df1f2d44c64fe634a4b1ed3ee819e2
5
5
  SHA512:
6
- metadata.gz: 73b60741536a682d32c26c96276694f7d0dcfc23110c1b4c410d7647186613e064311b4c22cca3c8d5522c856b98b54d4b51f90f6728f89686e26b299377a07a
7
- data.tar.gz: 2f586193dc34d876851a36d5510ff5fb69ca826e650f3b21a7aa2ea738346fe91cb0ffc2ce899e6232b7a9f1974be1bbfad8b79a3cf0c9be9f670edd9e3bcf0b
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
  [![Gem Version](https://badge.fury.io/rb/runfile.svg)](http://badge.fury.io/rb/runfile)
5
5
  [![Build Status](https://travis-ci.org/DannyBen/runfile.svg?branch=master)](https://travis-ci.org/DannyBen/runfile)
6
6
  [![Code Climate](https://codeclimate.com/github/DannyBen/runfile/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/runfile)
7
- [![Gem](https://img.shields.io/gem/dt/runfile.svg)](https://rubygems.org/gems/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) -->
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
@@ -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 => e
42
- abort "Runfile error:\n#{e.message}\n#{e.backtrace[0]}"
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
- @last_usage = name if @last_usage.nil?
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] = {} unless @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 => e
76
- puts e.message
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 => e
93
+ rescue Docopt::Exit => ex
88
94
  puts "Cross call failed: #{command_string}"
89
- abort e.message
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 |n|
118
- next unless argv.size >= n
119
- action = argv[0..n-1].join('_').to_sym
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
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
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.3.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-07-01 00:00:00.000000000 Z
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole