Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
language: ruby
rvm:
- 2.0.0
- 2.1.3
- 2.1.5
- 2.2.0
- 2.2.1
- 2.2.2
- 2.2.4
- 2.3.0
deploy:
provider: rubygems
gem: factor
Expand Down
104 changes: 39 additions & 65 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,102 +1,83 @@
PATH
remote: .
specs:
factor (2.9.08)
commander (~> 4.3, >= 4.3.4)
configatron (~> 4.5, >= 4.5.0)
rainbow (~> 2.0, >= 2.0.0)
rest-client (~> 1.8, >= 1.8.0)
rspec (~> 3.3, >= 3.3.0)
varify (~> 0.0.5)
wrong (~> 0.7.1)
factor (3.0.0)
commander (~> 4.4.0)
concurrent-ruby (~> 1.0.1)
configatron (~> 4.5.0)
rainbow (~> 2.1.0)

GEM
remote: https://rubygems.org/
specs:
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
commander (4.3.4)
coderay (1.1.1)
commander (4.4.0)
highline (~> 1.7.2)
concurrent-ruby (1.0.1)
configatron (4.5.0)
coveralls (0.8.1)
coveralls (0.8.13)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.10.0)
simplecov (~> 0.11.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.8)
formatador (0.2.5)
guard (2.12.6)
guard (2.13.0)
formatador (>= 0.2.4)
listen (~> 2.7)
listen (>= 2.7, <= 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.5.2)
guard-rspec (4.6.5)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
highline (1.7.2)
hitimes (1.2.2)
http-cookie (1.0.2)
domain_name (~> 0.5)
highline (1.7.8)
hitimes (1.2.3)
json (1.8.3)
listen (2.10.0)
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.9)
method_source (0.8.2)
mime-types (2.6.1)
nenv (0.2.0)
netrc (0.10.3)
notiffany (0.0.6)
nenv (~> 0.1)
shellany (~> 0.0)
predicated (0.2.6)
pry (0.10.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rainbow (2.0.0)
rake (10.4.2)
rainbow (2.1.0)
rake (11.1.2)
rb-fsevent (0.9.5)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.0)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.0)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
ruby2ruby (2.2.0)
ruby_parser (~> 3.1)
sexp_processor (~> 4.0)
ruby_parser (3.7.0)
sexp_processor (~> 4.1)
sexp_processor (4.6.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
shellany (0.0.1)
simplecov (0.10.0)
simplecov (0.11.2)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
Expand All @@ -107,24 +88,17 @@ GEM
thor (0.19.1)
timers (4.0.1)
hitimes
tins (1.5.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
varify (0.0.5)
wrong (0.7.1)
diff-lcs (~> 1.2.5)
predicated (~> 0.2.6)
ruby2ruby (>= 2.0.1)
ruby_parser (>= 3.0.1)
sexp_processor (>= 4.0)
tins (1.6.0)

PLATFORMS
ruby

DEPENDENCIES
coveralls (~> 0.8.1)
coveralls (~> 0.8.13)
factor!
guard (~> 2.12.6)
guard-rspec (~> 4.5.2)
rake (~> 10.4.2)
guard (~> 2.13.0)
guard-rspec (~> 4.6.5)
rake (~> 11.1.2)

BUNDLED WITH
1.11.2
19 changes: 8 additions & 11 deletions factor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ Gem::Specification.new do |s|
s.executables = ['factor']
s.require_paths = ['lib']

s.add_runtime_dependency 'commander', '~> 4.3', '>= 4.3.4'
s.add_runtime_dependency 'rainbow', '~> 2.0', '>= 2.0.0'
s.add_runtime_dependency 'configatron', '~> 4.5', '>= 4.5.0'
s.add_runtime_dependency 'rest-client', '~> 1.8', '>= 1.8.0'
s.add_runtime_dependency 'wrong', '~> 0.7.1'
s.add_runtime_dependency 'rspec', '~> 3.3', '>= 3.3.0'
s.add_runtime_dependency 'varify', '~> 0.0.5'
s.add_development_dependency 'coveralls', '~> 0.8.1'
s.add_development_dependency 'rake', '~> 10.4.2'
s.add_development_dependency 'guard', '~> 2.12.6'
s.add_development_dependency 'guard-rspec', '~> 4.5.2'
s.add_runtime_dependency 'commander', '~> 4.4.0'
s.add_runtime_dependency 'rainbow', '~> 2.1.0'
s.add_runtime_dependency 'configatron', '~> 4.5.0'
s.add_runtime_dependency 'concurrent-ruby', '~> 1.0.1'
s.add_development_dependency 'coveralls', '~> 0.8.13'
s.add_development_dependency 'rake', '~> 11.1.2'
s.add_development_dependency 'guard', '~> 2.13.0'
s.add_development_dependency 'guard-rspec', '~> 4.6.5'
end
17 changes: 9 additions & 8 deletions lib/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
program :version, Factor::VERSION
program :description, 'Factor.io Server to run workflows'

command 'server' do |c|
c.syntax = 'factor server [options]'
command 'workflow' do |c|
c.syntax = 'factor workflow workflow_file'
c.description = 'Start the Factor.io Server in the current local directory'
c.option '--log FILE', String, 'Log file path. Default is stdout.'
c.option '--credentials FILE', String, 'credentials.yml file path.'
c.option '--path FILE', String, 'Path to workflows'
c.when_called Factor::Commands::WorkflowCommand, :server
c.option '--settings FILE', String, 'factor.yml file path.'
c.option '--verbose', 'Verbose logging'
c.when_called Factor::Commands::WorkflowCommand, :run
end

command 'run' do |c|
c.syntax = 'factor run service_address params'
c.description = 'Run a specific command.'
c.option '--credentials FILE', String, 'credentials.yml file path.'
c.option '--connector FILE', String, 'file to require for loading method'
c.option '--verbose', 'Verbose logging'
c.when_called Factor::Commands::RunCommand, :run
end

alias_command 's', 'server'
alias_command 'w', 'workflow'
alias_command 'r', 'run'
74 changes: 47 additions & 27 deletions lib/factor/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,75 @@
require 'configatron'
require 'yaml'
require 'fileutils'
require 'factor/logger/basic'
require 'factor/logger'

module Factor
module Commands
# Base command with common methods used by all commands
class Command
attr_accessor :logger

DEFAULT_FILENAME = {
credentials: File.expand_path('./credentials.yml')
}
DEFAULT_FILENAME = File.expand_path('./settings.yml')

def initialize
@logger = Factor::Log::BasicLogger.new
@logger = Factor::Logger.new
end

def load_config(options = {})
load_config_data :credentials, options
def load_settings(options = {})
relative_path = options.settings || DEFAULT_FILENAME
absolute_path = File.expand_path(relative_path)
content = File.read(absolute_path)
data = YAML.load(content)
configatron[:settings].configure_from_hash(data)
end

def settings
configatron.settings.to_hash
end

protected

def info(message)
log(:info, message)
end

def warn(message)
log(:warn, message)
end

def save_config(options={})
credentials_relative_path = options[:credentials] || DEFAULT_FILENAME[:credentials]
credentials_absolute_path = File.expand_path(credentials_relative_path)
credentials = Hash[stringify(configatron.credentials.to_h).sort]
def error(message)
log(:error, message)
end

def success(message)
log(:success, message)
end

File.write(credentials_absolute_path,YAML.dump(credentials))
def log(type, message)
@logger.log(type, message) if @logger
end


private

def stringify(hash)
hash.inject({}) do |options, (key, value)|
options[key.to_s] = value.is_a?(Hash) ? stringify(value) : value
options
def try_json(value)
new_value = value
begin
new_value = JSON.parse(value, symbolize_names: true)
rescue JSON::ParserError
end
new_value
end

def load_config_data(config_type, options = {})
relative_path = options[config_type] || DEFAULT_FILENAME[config_type]
absolute_path = File.expand_path(relative_path)
begin
data = YAML.load(File.read(absolute_path))
rescue
data = {}

def params(args = [])
request_options = {}
args.each do |arg|
key,value = arg.split(/:/,2)
raise ArgumentError, "Option '#{arg}' is not a valid option" unless key && value
request_options[key.to_sym] = try_json(value)
end
configatron[config_type].configure_from_hash(data)
rescue => ex
logger.error message:"Couldn't load #{config_type} from #{absolute_path}", exception:ex
exit
request_options
end
end
end
Expand Down
Loading