Class: GlooLang::App::Args
- Inherits:
-
Object
- Object
- GlooLang::App::Args
- Defined in:
- lib/gloo_lang/app/args.rb
Constant Summary collapse
- QUIET =
'quiet'.freeze
- GLOO_ENV =
'GLOO_ENV'.freeze
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#switches ⇒ Object
readonly
Returns the value of attribute switches.
Instance Method Summary collapse
-
#cli? ⇒ Boolean
Is the cli switch set?.
-
#detect_mode ⇒ Object
Detect the mode to be run in.
-
#embed? ⇒ Boolean
Is the embed switch set?.
-
#help? ⇒ Boolean
Is the help switch set?.
-
#initialize(engine, params = []) ⇒ Args
constructor
Create arguments and setup.
-
#quiet? ⇒ Boolean
Was the –quiet arg passed?.
-
#version? ⇒ Boolean
Is the version switch set?.
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
#files ⇒ Object (readonly)
Returns the value of attribute files.
17 18 19 |
# File 'lib/gloo_lang/app/args.rb', line 17 def files @files end |
#switches ⇒ Object (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?
55 56 57 |
# File 'lib/gloo_lang/app/args.rb', line 55 def cli? @switches.include?( GlooLang::App::Mode::CLI.to_s ) end |
#detect_mode ⇒ Object
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 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?
62 63 64 |
# File 'lib/gloo_lang/app/args.rb', line 62 def @switches.include?( GlooLang::App::Mode::EMBED.to_s ) end |
#help? ⇒ Boolean
Is the help switch set?
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?
34 35 36 |
# File 'lib/gloo_lang/app/args.rb', line 34 def quiet? return @switches.include?( QUIET ) end |