console_runner 0.1.34 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/console_runner.gemspec +1 -2
- data/lib/command_line_parser.rb +7 -7
- data/lib/console_runner/version.rb +1 -1
- data/lib/method_parser.rb +3 -3
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a9dea09a8aec1d88e26ce1d6ab015aa0ecc6fda
|
4
|
+
data.tar.gz: 9429df62e79606d533a9bb71da143826c2687cb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a04c74c6351bee386d658b9ea135d593c49724f0c5c61d7f7f7365652927b3bcb4eb6cffbfd2f95e5b0543e09ae24a2e2c6d7d83f3958551a58d5098fa922e02
|
7
|
+
data.tar.gz: 02783cbbbe3975ff6575c454fadd83142150c3c08b5ca72546f138cbf2225a9b5e42458a39e4f41b153bf435b26fe7bc9abbbd26faf6ebc5bc2df3521d15ce5e
|
data/README.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
# ConsoleRunner
|
1
|
+
# ConsoleRunner [CLI for any *.rb]
|
2
2
|
[![Gem Version][GV img]][Gem Version]
|
3
3
|
[![Build Status][BS img]][Build Status]
|
4
|
-
[![Dependency Status][DS img]][Dependency Status]
|
5
4
|
[![Code Climate][CC img]][Code Climate]
|
6
5
|
[![Coverage Status][CS img]][Coverage Status]
|
7
6
|
|
8
7
|
This gem provides you an ability to run any Ruby method from command-line. No special code modifications required!.
|
9
|
-
`console_runner` is a smart mix of [YARD](http://yardoc.org/) and [
|
8
|
+
`console_runner` is a smart mix of [YARD](http://yardoc.org/) and [Optimist](http://manageiq.github.io/optimist/) gems.
|
10
9
|
It's an analog of [Python Fire](https://github.com/google/python-fire) in Ruby language.
|
11
10
|
> 1. it parses [YARD](http://yardoc.org/) annotations of classes and methods to 'understand' your code
|
12
|
-
> 2. it generates friendly unix-like help menu for your tool (using [
|
11
|
+
> 2. it generates friendly unix-like help menu for your tool (using [Optimist](http://manageiq.github.io/optimist/) gem)
|
13
12
|
> 3. it parses command-line input and run your Ruby code in a proper way
|
14
13
|
|
15
14
|
Just 4 simple steps to make your code runnable from terminal:
|
@@ -238,4 +237,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
238
237
|
[BS img]: https://travis-ci.org/yuri-karpovich/console_runner.svg?branch=master
|
239
238
|
[DS img]: https://gemnasium.com/badges/github.com/yuri-karpovich/console_runner.svg
|
240
239
|
[CC img]: https://codeclimate.com/github/yuri-karpovich/console_runner.png
|
241
|
-
[CS img]: https://coveralls.io/repos/github/yuri-karpovich/console_runner/badge.svg?branch=master
|
240
|
+
[CS img]: https://coveralls.io/repos/github/yuri-karpovich/console_runner/badge.svg?branch=master
|
data/console_runner.gemspec
CHANGED
@@ -32,13 +32,12 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = ['c_run']
|
33
33
|
spec.require_paths = ['lib']
|
34
34
|
|
35
|
-
spec.add_development_dependency 'bundler', '~> 1.13'
|
36
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
37
36
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
38
37
|
spec.add_development_dependency 'pry', '~> 0'
|
39
38
|
spec.add_development_dependency 'simplecov', '~> 0'
|
40
39
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
41
|
-
spec.add_dependency '
|
40
|
+
spec.add_dependency 'optimist', '~> 3.0'
|
42
41
|
spec.add_dependency 'yard', '~> 0.9'
|
43
42
|
spec.add_dependency 'colorize', '~> 0.8'
|
44
43
|
end
|
data/lib/command_line_parser.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'optimist'
|
2
2
|
require 'method_parser'
|
3
3
|
require 'colorize'
|
4
4
|
|
5
|
-
# Parses command line and configure #
|
5
|
+
# Parses command line and configure #Optimist
|
6
6
|
class CommandLineParser
|
7
7
|
attr_reader :method, :initialize_method
|
8
8
|
@debug = false
|
@@ -14,11 +14,11 @@ class CommandLineParser
|
|
14
14
|
@sub_commands = @file_parser.runnable_methods.map { |m| m.name.to_s }
|
15
15
|
@sub_commands_text = @file_parser.runnable_methods.map do |m|
|
16
16
|
[
|
17
|
-
|
18
|
-
|
17
|
+
m.name.to_s,
|
18
|
+
FileParser.select_runnable_tags(m).map(&:text).join("\n")
|
19
19
|
]
|
20
20
|
end.to_h
|
21
|
-
@parser =
|
21
|
+
@parser = Optimist::Parser.new
|
22
22
|
@parser.opt(:debug, 'Run in debug mode.', type: :flag)
|
23
23
|
@parser.stop_on @sub_commands
|
24
24
|
@initialize_method = nil
|
@@ -54,7 +54,7 @@ class CommandLineParser
|
|
54
54
|
end
|
55
55
|
return unless scope.any? { |a| %w(-h --help).include? a }
|
56
56
|
@parser.banner("\n" + banner)
|
57
|
-
|
57
|
+
Optimist::with_standard_exception_handling(@parser) { raise Optimist::HelpNeeded }
|
58
58
|
end
|
59
59
|
|
60
60
|
def raise_on_action_absence(sub_commands)
|
@@ -70,7 +70,7 @@ class CommandLineParser
|
|
70
70
|
@method = MethodParser.new action
|
71
71
|
[@initialize_method, @method].each do |method|
|
72
72
|
next unless method
|
73
|
-
method.
|
73
|
+
method.optimist_opts.each { |a| @parser.opt(*a) }
|
74
74
|
maybe_help(method.text, action.name.to_s)
|
75
75
|
cmd_opts = @parser.parse ARGV
|
76
76
|
given_attrs = cmd_opts.keys.select { |k| k.to_s.include? '_given' }.map { |k| k.to_s.gsub('_given', '').to_sym }
|
data/lib/method_parser.rb
CHANGED
@@ -6,7 +6,7 @@ class MethodParser
|
|
6
6
|
:parameters,
|
7
7
|
:param_tags, # All method parameters tags
|
8
8
|
:option_tags, # Only options tags
|
9
|
-
:
|
9
|
+
:optimist_opts,
|
10
10
|
:default_values,
|
11
11
|
:required_parameters
|
12
12
|
|
@@ -44,10 +44,10 @@ class MethodParser
|
|
44
44
|
Use different names to `console_runner` be able to run #{@name} method."
|
45
45
|
)
|
46
46
|
end
|
47
|
-
@
|
47
|
+
@optimist_opts = prepare_opts_for_optimist
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def prepare_opts_for_optimist
|
51
51
|
result = []
|
52
52
|
param_tags.each do |tag|
|
53
53
|
tag_name = tag.name
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Karpovich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.13'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.13'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,19 +81,19 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0.8'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: optimist
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '3.0'
|
104
90
|
type: :runtime
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '3.0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: yard
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|