mini_cli 0.0.1 → 0.1.0
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -5
- data/README.md +17 -8
- data/cli +15 -0
- data/lib/mini_cli/base.rb +6 -49
- data/lib/mini_cli/base_module.rb +66 -0
- data/lib/mini_cli/version.rb +1 -1
- data/lib/mini_cli.rb +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88b867e88d34b469c42cd338e2634d1f29f71549
|
4
|
+
data.tar.gz: e0ebeb0d82502d788aefd68909b5a22bd335ef7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf496d09953f5970961130dfa7bf406fa1f1988b49007a84f507a11bab8f35c4b60c90add5cc5f1547f8d1c263f733bcb23f8ec676243b3efc64d019c9ef2ad
|
7
|
+
data.tar.gz: f3683878236374c43037d3e397b2b08b9b72e40ce4797bf6b72eb669f5c82a96c37c4beaf2ada6b79a97cc99b33e447424c920cbf71797adab02ffbdff7599d5
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,8 +2,8 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
mini_cli (0.0.1)
|
5
|
-
puma
|
6
|
-
rerun
|
5
|
+
puma (~> 2.10)
|
6
|
+
rerun (~> 0.10)
|
7
7
|
thor (~> 0.19)
|
8
8
|
|
9
9
|
GEM
|
@@ -14,9 +14,10 @@ GEM
|
|
14
14
|
coderay (1.1.0)
|
15
15
|
diff-lcs (1.2.5)
|
16
16
|
ffi (1.9.6)
|
17
|
+
gem-release (0.7.3)
|
17
18
|
hitimes (1.2.2)
|
18
19
|
json (1.8.1)
|
19
|
-
listen (2.8.
|
20
|
+
listen (2.8.5)
|
20
21
|
celluloid (>= 0.15.2)
|
21
22
|
rb-fsevent (>= 0.9.3)
|
22
23
|
rb-inotify (>= 0.9)
|
@@ -27,7 +28,7 @@ GEM
|
|
27
28
|
coderay (~> 1.1.0)
|
28
29
|
method_source (~> 0.8.1)
|
29
30
|
slop (~> 3.4)
|
30
|
-
puma (2.
|
31
|
+
puma (2.11.1)
|
31
32
|
rack (>= 1.1, < 2.0)
|
32
33
|
rack (1.5.2)
|
33
34
|
rack-test (0.6.2)
|
@@ -60,9 +61,10 @@ PLATFORMS
|
|
60
61
|
|
61
62
|
DEPENDENCIES
|
62
63
|
bundler (~> 1.3)
|
64
|
+
gem-release
|
63
65
|
mini_check
|
64
66
|
mini_cli!
|
65
67
|
pry
|
66
68
|
rack-test
|
67
|
-
rake
|
69
|
+
rake (~> 10.4)
|
68
70
|
rspec
|
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# MiniCli
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
The idea behind MiniCli is that apps should provide a common entry point that is self-explanatory.
|
4
|
+
A single executable script that lists all you can do with the app and some help about it.
|
5
|
+
This makes it very easy for new developers to use your app.
|
6
|
+
I. e:
|
5
7
|
|
6
8
|
```
|
9
|
+
> ./cli
|
10
|
+
|
7
11
|
Commands:
|
8
12
|
cli auto [COMMAND] # Re-runs the given command on any file change
|
9
13
|
cli console # Pry console with the app available
|
@@ -12,15 +16,20 @@ Commands:
|
|
12
16
|
cli test # Run the test suite
|
13
17
|
```
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Inherit from MiniCli::Base to provide the basic commands:
|
19
|
+
MiniCli it provides a set of easy to include ready-made Thor commands to help achieve that.
|
20
|
+
Ideally, libraries that provides their own commands would also provide this easy to include commands:
|
19
21
|
|
20
22
|
```ruby
|
21
23
|
require 'mini_cli'
|
22
24
|
|
23
|
-
class
|
25
|
+
class CLI < Thor
|
26
|
+
include MiniCli::BaseModule
|
27
|
+
|
28
|
+
add_startup_benchmark
|
29
|
+
add_start_puma puma_args: %w{-p 22000}
|
30
|
+
add_console_pry
|
31
|
+
add_test_rspec
|
32
|
+
add_auto_rerun
|
24
33
|
end
|
25
34
|
```
|
26
35
|
|
@@ -30,7 +39,7 @@ Invoke it as a regular Thor class:
|
|
30
39
|
#!/usr/bin/env ruby
|
31
40
|
|
32
41
|
require_relative 'cli'
|
33
|
-
|
42
|
+
CLI.start
|
34
43
|
```
|
35
44
|
|
36
45
|
|
data/cli
ADDED
data/lib/mini_cli/base.rb
CHANGED
@@ -3,55 +3,12 @@ require 'thor'
|
|
3
3
|
module MiniCli
|
4
4
|
# The base class to inherit from to provide the basic commands of a microservice
|
5
5
|
class Base < Thor
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'test', 'Run the test suite'
|
15
|
-
def test *args
|
16
|
-
args = ['spec'] if args.empty?
|
17
|
-
|
18
|
-
require 'spec/spec_helper'
|
19
|
-
|
20
|
-
RSpec::Core::Runner.run(args)
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'console', 'Pry console with the app available'
|
24
|
-
def console
|
25
|
-
require'pry'
|
26
|
-
Pry.start
|
27
|
-
end
|
28
|
-
|
29
|
-
desc 'auto [COMMAND]', 'Re-runs the given command on any file change'
|
30
|
-
long_desc 'Re-runs the given command on any file change.' +
|
31
|
-
" I. e. \"#{$0} auto test\" will run the tests on each file save."
|
32
|
-
def auto *args
|
33
|
-
require 'rerun'
|
34
|
-
|
35
|
-
options = Rerun::Options.parse [
|
36
|
-
'--background',
|
37
|
-
'--name', "./cli #{args.first}",
|
38
|
-
'--signal', 'ABRT',
|
39
|
-
]
|
40
|
-
|
41
|
-
Rerun::Runner.keep_running("./cli #{args.join " "}", options)
|
42
|
-
end
|
43
|
-
|
44
|
-
desc 'start', 'Starts the Puma and any other required thread'
|
45
|
-
def start
|
46
|
-
require 'puma/cli'
|
47
|
-
Puma::CLI.new(puma_args).run
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def puma_args
|
53
|
-
%w{-p 22000}
|
54
|
-
end
|
6
|
+
include BaseModule
|
7
|
+
add_startup_benchmark
|
8
|
+
add_start_puma puma_args: %w{-p 22000}
|
9
|
+
add_console_pry
|
10
|
+
add_test_rspec
|
11
|
+
add_auto_rerun
|
55
12
|
end
|
56
13
|
end
|
57
14
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module MiniCli
|
2
|
+
# Provides class methods for individual definition of ready-made commands
|
3
|
+
module BaseModule
|
4
|
+
module ClassMethods
|
5
|
+
def add_console_pry
|
6
|
+
desc 'console', 'Pry console with the app available'
|
7
|
+
define_method :console do
|
8
|
+
require'pry'
|
9
|
+
Pry.start
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_test_rspec
|
14
|
+
desc 'test', 'Run the test suite'
|
15
|
+
define_method :test do |*args|
|
16
|
+
args = ['spec'] if args.empty?
|
17
|
+
require 'rspec'
|
18
|
+
RSpec::Core::Runner.run(args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_auto_rerun
|
23
|
+
desc 'auto [COMMAND]', 'Re-runs the given command on any file change'
|
24
|
+
long_desc 'Re-runs the given command on any file change.' +
|
25
|
+
" I. e. \"#{$0} auto test\" will run the tests on each file save."
|
26
|
+
define_method :auto do |*args|
|
27
|
+
require 'rerun'
|
28
|
+
|
29
|
+
options = Rerun::Options.parse [
|
30
|
+
'--background',
|
31
|
+
'--name', "./cli #{args.first}",
|
32
|
+
'--signal', 'ABRT',
|
33
|
+
]
|
34
|
+
|
35
|
+
Rerun::Runner.keep_running("./cli #{args.join " "}", options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_start_puma opts = {}
|
40
|
+
opts = opts.dup
|
41
|
+
puma_args = opts.delete(:puma_args) || []
|
42
|
+
raise("Unrecognized options #{opts.inspect}") if opts.keys.any?
|
43
|
+
|
44
|
+
desc 'start', 'Starts the Puma and any other required thread'
|
45
|
+
define_method :start do
|
46
|
+
require 'puma/cli'
|
47
|
+
Puma::CLI.new(puma_args).run
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_startup_benchmark
|
52
|
+
# Shows execution time to the end of the run
|
53
|
+
def self.start
|
54
|
+
require 'benchmark'
|
55
|
+
bm = Benchmark.measure { |x| super }
|
56
|
+
puts "\n#{bm.total.round(3)}s task run time"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.included klass
|
62
|
+
klass.extend ClassMethods
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/lib/mini_cli/version.rb
CHANGED
data/lib/mini_cli.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Morales
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -93,8 +93,10 @@ files:
|
|
93
93
|
- LICENSE.txt
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
|
+
- cli
|
96
97
|
- lib/mini_cli.rb
|
97
98
|
- lib/mini_cli/base.rb
|
99
|
+
- lib/mini_cli/base_module.rb
|
98
100
|
- lib/mini_cli/version.rb
|
99
101
|
- mini_cli.gemspec
|
100
102
|
- spec/mini_cli/base_spec.rb
|