Sha256: f9ef07fd9e05d652923e023c66995eff5d4e5b1e759cc79622e959c43ca50a94

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

# encoding: UTF-8
# frozen_string_literal: true

# Refinements
# =======================================================================

using NRSER
using NRSER::Types


# Definitions
# =======================================================================

module NRSER::Rash::CLI
  
  # start here.
  #
  # this is the entry point for the script when executed. it expects a
  # command as the first argument and dispatches to the associated method.
  def self.run
    SemanticLogger.add_appender io: $stderr, formatter: {
      color: {
        ap: {multiline: true},
      }
    }
    SemanticLogger.default_level = NRSER::Rash.config( 'LOG_LEVEL' ).to_sym
    
    # the command is the first argument
    # we won't need or want it after this, so delete it
    command = ARGV.shift
    # filter out the command line config options
    NRSER::Rash.filter_and_set_config ARGV
    case command
    when 'call'
      # we are being asked to call a function. the name of the function is
      # the second argument (now at index 0 since we deleted the command)
      # and the rest of the arguments are passed to the function
      call ARGV[0], ARGV[1..-1]
    when 'test'
      NRSER::Rash._test_function ARGV.shift #, ARGV[1, ARGV.length]
    when 'list'
      list
    when 'help', '-h', '--help', nil
      help
      # Exit with error so these calls don't work with `&&` in shell
      exit 1
    when '--version', 'version', '-v'
      puts NRSER::Rash::VERSION
    else
      call command, ARGV
    end
  end
  
end # module NRSER::Rash::CLI

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nrser-rash-0.2.3 lib/nrser/rash/cli/run.rb
nrser-rash-0.2.2 lib/nrser/rash/cli/run.rb
nrser-rash-0.2.1 lib/nrser/rash/cli/run.rb
nrser-rash-0.2.0 lib/nrser/rash/cli/run.rb