Class: GlooLang::App::Args

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/app/args.rb

Constant Summary collapse

QUIET =
'quiet'.freeze
GLOO_ENV =
'GLOO_ENV'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, params = []) ⇒ Args

Create arguments and setup.



22
23
24
25
26
27
28
29
# File 'lib/gloo_lang/app/args.rb', line 22

def initialize( engine, params = [] )
  @engine = engine
  @switches = []
  @files = []

  params.each { |o| process_one_arg( o ) }
  ARGV.each { |o| process_one_arg( o ) }
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



17
18
19
# File 'lib/gloo_lang/app/args.rb', line 17

def files
  @files
end

#switchesObject (readonly)

Returns the value of attribute switches.



17
18
19
# File 'lib/gloo_lang/app/args.rb', line 17

def switches
  @switches
end

Instance Method Details

#cli?Boolean

Is the cli switch set?

Returns:

  • (Boolean)


55
56
57
# File 'lib/gloo_lang/app/args.rb', line 55

def cli?
  @switches.include?( GlooLang::App::Mode::CLI.to_s )
end

#detect_modeObject

Detect the mode to be run in. Start by seeing if a mode is specified. Then look for the presence of files. Then finally use the default: embedded mode.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gloo_lang/app/args.rb', line 72

def detect_mode
  mode = if ENV[ GLOO_ENV ] == GlooLang::App::Mode::TEST.to_s
           Mode::TEST
         elsif version?
           Mode::VERSION
         elsif help?
           Mode::HELP
         elsif cli?
           Mode::CLI
         elsif embed?
           Mode::EMBED
         elsif @files.count.positive?
           Mode::SCRIPT
         else
           Mode.default_mode
         end
  @engine.log.debug "running in #{mode} mode"

  return mode
end

#embed?Boolean

Is the embed switch set?

Returns:

  • (Boolean)


62
63
64
# File 'lib/gloo_lang/app/args.rb', line 62

def embed?
  @switches.include?( GlooLang::App::Mode::EMBED.to_s )
end

#help?Boolean

Is the help switch set?

Returns:

  • (Boolean)


48
49
50
# File 'lib/gloo_lang/app/args.rb', line 48

def help?
  @switches.include?( GlooLang::App::Mode::HELP.to_s )
end

#quiet?Boolean

Was the –quiet arg passed?

Returns:

  • (Boolean)


34
35
36
# File 'lib/gloo_lang/app/args.rb', line 34

def quiet?
  return @switches.include?( QUIET )
end

#version?Boolean

Is the version switch set?

Returns:

  • (Boolean)


41
42
43
# File 'lib/gloo_lang/app/args.rb', line 41

def version?
  @switches.include?( GlooLang::App::Mode::VERSION.to_s )
end