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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea711692c0f25baafc371451a02dbe2dbbe9b614
4
- data.tar.gz: 1ebaa4205176286a479a8d9e466fb6a76240cda4
3
+ metadata.gz: 88b867e88d34b469c42cd338e2634d1f29f71549
4
+ data.tar.gz: e0ebeb0d82502d788aefd68909b5a22bd335ef7f
5
5
  SHA512:
6
- metadata.gz: cd18091197c638be75652bf314754ad35045d50b4a84501c893bddbfffe5ffc144caf24f14239586dd230b727aa632708ba60048f51f0904b62a570febf71c64
7
- data.tar.gz: 8ede5324662a3523139ea07b98c3605de469b9df890c63facdeda59dba23fc1839f7bc04fa0360be0113b43d21d5fdf35f6c62a1c4c2c366d13d182153b4330c
6
+ metadata.gz: acf496d09953f5970961130dfa7bf406fa1f1988b49007a84f507a11bab8f35c4b60c90add5cc5f1547f8d1c263f733bcb23f8ec676243b3efc64d019c9ef2ad
7
+ data.tar.gz: f3683878236374c43037d3e397b2b08b9b72e40ce4797bf6b72eb669f5c82a96c37c4beaf2ada6b79a97cc99b33e447424c920cbf71797adab02ffbdff7599d5
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  tags
2
+ *.gem
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test, :development do
6
+ gem 'gem-release'
6
7
  gem 'mini_check', require: false
7
8
  gem 'rspec', require: false
8
9
  gem 'pry', require: false
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.3)
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.10.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
- Simple command line interface for microservices built using Thor.
4
- It provides basic commands:
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
- ## Usage
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 Cli < MiniCli::Base
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
- PatioSessions::Cli.start
42
+ CLI.start
34
43
  ```
35
44
 
36
45
 
data/cli ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.require(:test, :default, :development)
5
+
6
+ require 'thor'
7
+ require_relative 'lib/mini_cli'
8
+
9
+ class CLI < Thor
10
+ include MiniCli::BaseModule
11
+ add_test_rspec
12
+ end
13
+
14
+ CLI.start
15
+
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
- # Shows execution time to the end of the run
8
- def self.start
9
- require 'benchmark'
10
- bm = Benchmark.measure { |x| super }
11
- puts "\n#{bm.total.round(3)}s task run time"
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
+
@@ -1,3 +1,3 @@
1
1
  module MiniCli
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/mini_cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "mini_cli/version"
2
2
 
3
3
  module MiniCli
4
- autoload :Base, 'mini_cli/base'
4
+ require_relative 'mini_cli/base_module'
5
+ require_relative 'mini_cli/base'
5
6
  end
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.1
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-13 00:00:00.000000000 Z
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