Class: Opener::ChainedDaemon::CLI
- Inherits:
-
Object
- Object
- Opener::ChainedDaemon::CLI
- Defined in:
- lib/opener/chained_daemon/cli.rb
Overview
CLI wrapper around Opener::ChainedDaemon using Slop.
Instance Attribute Summary collapse
- #parser ⇒ Slop readonly
Instance Method Summary collapse
- #configure_slop ⇒ Slop
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(argv = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
13 14 15 |
# File 'lib/opener/chained_daemon/cli.rb', line 13 def initialize @parser = configure_slop end |
Instance Attribute Details
#parser ⇒ Slop (readonly)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/opener/chained_daemon/cli.rb', line 9 class CLI attr_reader :parser def initialize @parser = configure_slop end ## # @param [Array] argv # def run argv = ARGV parser.parse argv end ## # @return [Slop] # def configure_slop Slop.new strict: false, indent: 2, help: true do 'Usage: chained-daemon [OPTIONS]' separator <<-EOF.chomp About: Example: cat some_file.kaf | chained-daemon EOF separator "\nOptions:\n" on :v, :version, 'Shows the current version' do abort "chained-daemon v#{VERSION} on #{RUBY_DESCRIPTION}" end run do |opts, args| daemon = ChainedDaemon.new args: args input = STDIN.tty? ? nil : STDIN.read params = if ENV['PARAMS'] then JSON.parse ENV['PARAMS'] else {} end # Set environment as staging from console for testing purposes env = ENV['LEXICONS_ENV'] || 'staging' pt = ENV['LEXICONS_PROPERTY_TYPE'] params[:language] = ENV['OVERRIDE_LANGUAGE'] params[:cache_keys] = { environment: env, property_type: pt, merged: (true if env == 'staging'), } output = daemon.run input, params puts output end end end end |
Instance Method Details
#configure_slop ⇒ Slop
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/opener/chained_daemon/cli.rb', line 27 def configure_slop Slop.new strict: false, indent: 2, help: true do 'Usage: chained-daemon [OPTIONS]' separator <<-EOF.chomp About: Example: cat some_file.kaf | chained-daemon EOF separator "\nOptions:\n" on :v, :version, 'Shows the current version' do abort "chained-daemon v#{VERSION} on #{RUBY_DESCRIPTION}" end run do |opts, args| daemon = ChainedDaemon.new args: args input = STDIN.tty? ? nil : STDIN.read params = if ENV['PARAMS'] then JSON.parse ENV['PARAMS'] else {} end # Set environment as staging from console for testing purposes env = ENV['LEXICONS_ENV'] || 'staging' pt = ENV['LEXICONS_PROPERTY_TYPE'] params[:language] = ENV['OVERRIDE_LANGUAGE'] params[:cache_keys] = { environment: env, property_type: pt, merged: (true if env == 'staging'), } output = daemon.run input, params puts output end end end |
#run(argv = ARGV) ⇒ Object
20 21 22 |
# File 'lib/opener/chained_daemon/cli.rb', line 20 def run argv = ARGV parser.parse argv end |