runfile 0.3.2 → 0.3.3

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: b2a0ccfa3a80cd356498b5a90abc45d2f799e36c
4
- data.tar.gz: 343fb0c27e72cd670943ba0a8050efe92d3ccaf0
3
+ metadata.gz: 4b3f76f9bd21810f1bcec6852443b345ed34b96b
4
+ data.tar.gz: e0a618c50953691f9c4e8e03d6a07d889406b2c7
5
5
  SHA512:
6
- metadata.gz: e172263529326fc9fd885faea650cacb0cbd08ffa35fe3222f9ffae3f42f73cd3fa642cbe74ad911ef0fad91286113f3aa04758b625744706aa0d04316bb9e69
7
- data.tar.gz: bb064103aefc63311412ed55344c75183c8727d08304916013830a5840e252d8914588880aa7e9680cbb37023a9a53732ee576f999459724e83057f6339b4bc6
6
+ metadata.gz: 73b60741536a682d32c26c96276694f7d0dcfc23110c1b4c410d7647186613e064311b4c22cca3c8d5522c856b98b54d4b51f90f6728f89686e26b299377a07a
7
+ data.tar.gz: 2f586193dc34d876851a36d5510ff5fb69ca826e650f3b21a7aa2ea738346fe91cb0ffc2ce899e6232b7a9f1974be1bbfad8b79a3cf0c9be9f670edd9e3bcf0b
data/README.md CHANGED
@@ -3,6 +3,8 @@ Runfile - If Rake and Docopt had a baby
3
3
 
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
+ [![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)
6
8
 
7
9
  A beautiful command line application framework.
8
10
  Rake-inspired, Docopt inside.
@@ -25,34 +25,58 @@ module Runfile
25
25
  # and options we have collected from the Runfile DSL.
26
26
  def docopt
27
27
  width, height = detect_terminal_size
28
- doc = "#{@name} #{@version}\n"
29
- doc += "#{@summary} \n" if @summary
30
- doc += "\nUsage:\n";
28
+ doc = ["#{@name} #{@version}"]
29
+ doc << "#{@summary}" if @summary
30
+ doc += docopt_usage
31
+ doc += docopt_commands width
32
+ doc += docopt_options width
33
+ doc.join "\n"
34
+ end
35
+
36
+ # Return all docopt lines for the 'Usage' section
37
+ def docopt_usage
38
+ doc = ["\nUsage:"];
31
39
  @actions.each do |name, action|
32
- doc += " run #{action.usage}\n" unless action.usage == false
40
+ doc << " run #{action.usage}" unless action.usage == false
33
41
  end
34
- doc += " run ( -h | --help | --version )\n\n"
42
+ doc << " run ( -h | --help | --version )\n"
43
+ doc
44
+ end
45
+
46
+ # Return all docopt lines for the 'Commands' section
47
+ def docopt_commands(width)
48
+ doc = []
35
49
  caption_printed = false
36
50
  @actions.each do |name, action|
37
51
  action.help or next
38
- doc += "Commands:\n" unless caption_printed
52
+ doc << "Commands:" unless caption_printed
39
53
  caption_printed = true
40
54
  helpline = " #{action.help}"
41
55
  wrapped = word_wrap helpline, width
42
- doc += " #{action.usage}\n#{wrapped}\n\n" unless action.usage == false
56
+ doc << " #{action.usage}\n#{wrapped}\n" unless action.usage == false
43
57
  end
44
- doc += "Options:\n"
45
- doc += " -h --help\n Show this screen\n\n"
46
- doc += " --version\n Show version\n\n"
47
- @options.each do |flag, text|
48
- helpline = " #{text}"
49
- wrapped = word_wrap helpline, width
50
- doc += " #{flag}\n#{wrapped}\n\n"
58
+ doc
59
+ end
60
+
61
+ # Return all docopt lines for the various 'Options' sections
62
+ def docopt_options(width)
63
+ @options['Options'] = {} unless @options['Options']
64
+ @options['Options']['-h --help'] = 'Show this screen'
65
+ @options['Options']['--version'] = 'Show version number'
66
+
67
+ doc = []
68
+ @options.each do |scope, values|
69
+ doc << "#{scope}:"
70
+ values.each do |flag, text|
71
+ helpline = " #{text}"
72
+ wrapped = word_wrap helpline, width
73
+ doc << " #{flag}\n#{wrapped}\n"
74
+ end
51
75
  end
52
76
  doc
53
77
  end
54
78
 
55
- # Calls the docopt handler, which will either return a parsed
79
+ # Call the docopt handler, which will either return a parsed
56
80
  # arguments list, or halt execution and show usage.
57
81
  def args(argv)
58
82
  Docopt::docopt(docopt, version: @version, argv:argv)
data/lib/runfile/dsl.rb CHANGED
@@ -30,8 +30,8 @@ module Runfile
30
30
 
31
31
  # Add an option/flag to the next action (can be called multiple
32
32
  # times)
33
- def option(flag, text)
34
- Runner.instance.add_option flag, text
33
+ def option(flag, text, scope=nil)
34
+ Runner.instance.add_option flag, text, scope
35
35
  end
36
36
 
37
37
  # Define the action
@@ -72,16 +72,7 @@ module Runfile
72
72
  say "\n!txtred!Runfile not found."
73
73
  else
74
74
  say ""
75
- max = runfiles.max_by(&:length).size
76
- width, height = detect_terminal_size
77
- runfiles.each do |f|
78
- f[/([^\/]+).runfile$/]
79
- command = "run #{$1}"
80
- spacer_size = width - max - command.size - 6
81
- spacer_size = [1, spacer_size].max
82
- spacer = '.' * spacer_size
83
- say " !txtgrn!#{command}!txtrst! #{spacer} #{f}"
84
- end
75
+ say_runfile_list runfiles
85
76
  end
86
77
  end
87
78
 
@@ -92,5 +83,19 @@ module Runfile
92
83
  dirs
93
84
  end
94
85
 
86
+ # Output the list of available runfiles
87
+ def say_runfile_list(runfiles)
88
+ max = runfiles.max_by(&:length).size
89
+ width, height = detect_terminal_size
90
+ runfiles.each do |f|
91
+ f[/([^\/]+).runfile$/]
92
+ command = "run #{$1}"
93
+ spacer_size = width - max - command.size - 6
94
+ spacer_size = [1, spacer_size].max
95
+ spacer = '.' * spacer_size
96
+ say " !txtgrn!#{command}!txtrst! #{spacer} #{f}"
97
+ end
98
+ end
99
+
95
100
  end
96
101
  end
@@ -48,22 +48,22 @@ module Runfile
48
48
  # usage and help messages sent by the DSL.
49
49
  def add_action(name, &block)
50
50
  @last_usage = name if @last_usage.nil?
51
- if @namespace
52
- name = "#{namespace}_#{name}".to_sym
53
- @last_usage = "#{@namespace} #{@last_usage}" unless @last_usage == false
54
- end
55
- if @superspace
56
- name = "#{superspace}_#{name}".to_sym
57
- @last_usage = "#{@superspace} #{@last_usage}" unless @last_usage == false
51
+ [@namespace, @superspace].each do |prefix|
52
+ prefix or next
53
+ name = "#{prefix}_#{name}"
54
+ @last_usage = "#{prefix} #{last_usage}" unless @last_usage == false
58
55
  end
56
+ name = name.to_sym
59
57
  @actions[name] = Action.new(block, @last_usage, @last_help)
60
58
  @last_usage = nil
61
59
  @last_help = nil
62
60
  end
63
61
 
64
62
  # Add an option flag and its help text.
65
- def add_option(flag, text)
66
- @options[flag] = text
63
+ def add_option(flag, text, scope=nil)
64
+ scope or scope = 'Options'
65
+ @options[scope] = {} unless @options[scope]
66
+ @options[scope][flag] = text
67
67
  end
68
68
 
69
69
  # Run the command. This is a wrapper around docopt. It will
@@ -110,12 +110,16 @@ module Runfile
110
110
  # finally for a. This is intended to allow "overloading" of
111
111
  # the command as an action (e.g. also allow a global action
112
112
  # called 'a').
113
+ # if no command was found, but we have a :global command,
114
+ # assume this is the requested one (since we will not reach
115
+ # this point unless the usage pattern matches).
113
116
  def find_action(argv)
114
117
  3.downto(1).each do |n|
115
118
  next unless argv.size >= n
116
119
  action = argv[0..n-1].join('_').to_sym
117
120
  return action if @actions.has_key? action
118
121
  end
122
+ return :global if @actions.has_key? :global
119
123
  return false
120
124
  end
121
125
 
data/lib/runfile/util.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Runfile
2
2
  # Debug print and exit
3
3
  def d(obj)
4
- p obj
4
+ pp obj
5
5
  exit
6
6
  end
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.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.3.2
4
+ version: 0.3.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: 2015-06-13 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole