Skip to content

Commit

Permalink
CLI interface based on Thor
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Aug 22, 2019
1 parent 716691e commit 9dc0622
Show file tree
Hide file tree
Showing 24 changed files with 270 additions and 238 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
ignore
.DS_Store

/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/


26 changes: 26 additions & 0 deletions .rspec_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
example_id | status | run_time |
-------------------------------- | ------ | --------------- |
./spec/command_spec.rb[1:2] | passed | 0.00356 seconds |
./spec/message_spec.rb[1:1:1] | passed | 0.00092 seconds |
./spec/message_spec.rb[1:1:2] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:1:3] | passed | 0.00012 seconds |
./spec/message_spec.rb[1:1:4] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:1:5] | passed | 0.00039 seconds |
./spec/message_spec.rb[1:2:1] | passed | 0.00073 seconds |
./spec/message_spec.rb[1:2:2] | passed | 0.00011 seconds |
./spec/message_spec.rb[1:2:3] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:2:4] | passed | 0.00014 seconds |
./spec/message_spec.rb[1:2:5] | passed | 0.00094 seconds |
./spec/message_spec.rb[1:2:6] | passed | 0.00147 seconds |
./spec/message_spec.rb[1:2:7] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:2:8] | passed | 0.00005 seconds |
./spec/message_spec.rb[1:2:9] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:3:1] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:3:2] | passed | 0.00011 seconds |
./spec/message_spec.rb[1:3:3] | passed | 0.00008 seconds |
./spec/message_spec.rb[1:3:4] | passed | 0.00006 seconds |
./spec/message_spec.rb[1:3:5] | passed | 0.00007 seconds |
./spec/rsmp_spec.rb[1:1] | passed | 0.00046 seconds |
./spec/supervisor_spec.rb[1:1:1] | passed | 0.00008 seconds |
./spec/supervisor_spec.rb[1:1:2] | passed | 0.00006 seconds |
./spec/supervisor_spec.rb[1:1:3] | passed | 0.00988 seconds |
18 changes: 3 additions & 15 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# frozen_string_literal: true
source "https://rubygems.org"

source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'async'
gem 'async-io'
gem 'colorize'

group :test do
gem 'rspec'
gem 'rspec-expectations'
gem 'timecop'
gem 'rspec-with_params'
end
# Specify your gem's dependencies in rsmp.gemspec
gemspec
59 changes: 52 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
PATH
remote: .
specs:
rsmp (0.1.0)
async (~> 1.20.1)
async-io (~> 1.24.0)
colorize (~> 0.8.1)
thor

GEM
remote: https://rubygems.org/
specs:
aruba (0.14.11)
childprocess (>= 0.6.3, < 3.0.0)
contracts (~> 0.9)
cucumber (>= 1.3.19)
ffi (~> 1.9)
rspec-expectations (>= 2.99)
thor (~> 0.19)
async (1.20.1)
console (~> 1.0)
nio4r (~> 2.3)
timers (~> 4.1)
async-io (1.24.0)
async (~> 1.14)
backports (3.15.0)
builder (3.2.3)
childprocess (2.0.0)
rake (< 13.0)
colorize (0.8.1)
console (1.4.0)
contracts (0.16.0)
cucumber (3.1.2)
builder (>= 2.1.2)
cucumber-core (~> 3.2.0)
cucumber-expressions (~> 6.0.1)
cucumber-wire (~> 0.0.1)
diff-lcs (~> 1.3)
gherkin (~> 5.1.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (3.2.1)
backports (>= 3.8.0)
cucumber-tag_expressions (~> 1.1.0)
gherkin (~> 5.0)
cucumber-expressions (6.0.1)
cucumber-tag_expressions (1.1.1)
cucumber-wire (0.0.1)
diff-lcs (1.3)
ffi (1.11.1)
gherkin (5.1.0)
multi_json (1.13.1)
multi_test (0.1.2)
nio4r (2.4.0)
rake (10.5.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -26,20 +68,23 @@ GEM
rspec-support (3.8.0)
rspec-with_params (0.2.0)
rspec (~> 3.0)
thor (0.20.3)
timecop (0.9.1)
timers (4.3.0)

PLATFORMS
ruby

DEPENDENCIES
async
async-io
colorize
rspec
rspec-expectations
rspec-with_params
timecop
aruba (~> 0.14.11)
bundler (~> 2.0)
cucumber (~> 3.1.2)
rake (~> 10.0)
rsmp!
rspec (~> 3.0)
rspec-expectations (~> 3.8.3)
rspec-with_params (~> 0.2.0)
timecop (~> 0.9.1)

BUNDLED WITH
2.0.2
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
14 changes: 14 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "rsmp"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
51 changes: 0 additions & 51 deletions bin/site

This file was deleted.

58 changes: 0 additions & 58 deletions bin/supervisor

This file was deleted.

3 changes: 3 additions & 0 deletions exe/rsmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require 'rsmp/cli'
RSMP::CLI.start
5 changes: 5 additions & 0 deletions features/help.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Help

Scenario: Displaying help
When I run `rsmp help`
Then the output should contain "options"
9 changes: 9 additions & 0 deletions features/site.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Run site

Scenario: Run with no options
When I run `rsmp site`
Then the output should contain "Starting site"

Scenario: Port option
When I run `rsmp site --port 12117`
Then the output should contain "Starting site on port 12117"
1 change: 1 addition & 0 deletions features/support/setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'aruba/cucumber'
1 change: 1 addition & 0 deletions features/support/site.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_id: AXV
11 changes: 11 additions & 0 deletions lib/rsmp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "rsmp/version"
require "rsmp/supervisor"
require "rsmp/site"
require "rsmp/supervisor_connector"
require "rsmp/site_connector"
require "rsmp/error"
require "rsmp/probe"
require "rsmp/probe_collection"
require "rsmp/message"
require "rsmp/logger"
require "rsmp/archive"
52 changes: 52 additions & 0 deletions lib/rsmp/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'thor'
require 'rsmp'

module RSMP
class CLI < Thor

desc "site", "Run RSMP site"
method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
method_option :supervisors, :type => :string, :aliases => "-s", banner: 'ip:port,... list of supervisor to connect to'
def site
converted = {
site_settings_path: options[:config],
site_settings: {
site_id: options[:id],
}
}

if options[:supervisors]
options[:supervisors].split(',').each do |supervisor|
converted[:site_settings][:supervisors] ||= []
ip, port = supervisor.split ':'
ip = '127.0.0.1' if ip.empty?
port = '12111' if port.empty?
converted[:site_settings][:supervisors] << {"ip"=>ip, "port"=>port}
end
end

converted[:site_settings].compact!
RSMP::Site.new(converted).start
end

desc "supervisor", "Run RSMP supervisor"
method_option :config, :type => :string, :aliases => "-c", banner: 'Path to .yaml config file'
method_option :id, :type => :string, :aliases => "-i", banner: 'RSMP site id'
method_option :ip, :type => :numeric, banner: 'IP address to listen on'
method_option :port, :type => :string, :aliases => "-p", banner: 'Port to listen on'
def supervisor
converted = {
supervisor_settings_path: options[:config],
supervisor_settings: {
site_id: options[:id],
ip: options[:ip],
port: options[:port]
}
}
converted[:supervisor_settings].compact!
RSMP::Supervisor.new(converted).start
end

end
end
Loading

0 comments on commit 9dc0622

Please sign in to comment.