Class: Gloo::App::Args

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/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
30
# File 'lib/gloo/app/args.rb', line 22

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

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

Instance Attribute Details

#app_pathObject (readonly)

Returns the value of attribute app_path.



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

def app_path
  @app_path
end

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

#switchesObject (readonly)

Returns the value of attribute switches.



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

def switches
  @switches
end

Instance Method Details

#app?Boolean

Is the app switch set?

Returns:

  • (Boolean)


42
43
44
# File 'lib/gloo/app/args.rb', line 42

def app?
  @switches.include?( Gloo::App::Mode::APP.to_s )
end

#cli?Boolean

Is the cli switch set?

Returns:

  • (Boolean)


84
85
86
# File 'lib/gloo/app/args.rb', line 84

def cli?
  @switches.include?( Gloo::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.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gloo/app/args.rb', line 101

def detect_mode
  mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
           Mode::TEST
         elsif app?
           Mode::APP
         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

  mode = Mode::CLI unless verify_app_mode
  @engine.log.debug "running in #{mode} mode"

  return mode
end

#embed?Boolean

Is the embed switch set?

Returns:

  • (Boolean)


91
92
93
# File 'lib/gloo/app/args.rb', line 91

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

#help?Boolean

Is the help switch set?

Returns:

  • (Boolean)


77
78
79
# File 'lib/gloo/app/args.rb', line 77

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

#quiet?Boolean

Was the –quiet arg passed?

Returns:

  • (Boolean)


35
36
37
# File 'lib/gloo/app/args.rb', line 35

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

#verify_app_modeObject

Make sure that if we are running in App mode that the app path has been set and is a valid path.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gloo/app/args.rb', line 50

def verify_app_mode
  return true unless app?

  if @app_path.nil?
    @engine.err "App Path required to run in App mode."
    return false
  end

  unless File.directory? @app_path
    @engine.err "'#{@app_path}' is not a valid directory."
    return false
  end

  @engine.log.info "App root directory: '#{@app_path}'."
  return true
end

#version?Boolean

Is the version switch set?

Returns:

  • (Boolean)


70
71
72
# File 'lib/gloo/app/args.rb', line 70

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