Class: RGovData::Shell

Inherits:
Object
  • Object
show all
Includes:
CommonConfig
Defined in:
lib/rgovdata/shell/shell.rb

Constant Summary collapse

OPTIONS =

command line options definition

%w(help verbose command=@s)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonConfig

#config, #require_config_file

Constructor Details

#initialize(options) ⇒ Shell

new



40
41
42
43
44
# File 'lib/rgovdata/shell/shell.rb', line 40

def initialize(options)
  require_config_file
  @options = (options||{}).each{|k,v| {k => v} }
  @discovery_path = [config.default_realm].compact
end

Instance Attribute Details

#discovery_pathObject

Returns the value of attribute discovery_path.



4
5
6
# File 'lib/rgovdata/shell/shell.rb', line 4

def discovery_path
  @discovery_path
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/rgovdata/shell/shell.rb', line 3

def options
  @options
end

#prompt=(value) ⇒ Object

Sets the attribute prompt

Parameters:

  • value

    the value to set the attribute prompt to.



3
4
5
# File 'lib/rgovdata/shell/shell.rb', line 3

def prompt=(value)
  @prompt = value
end

Class Method Details

.usageObject

Usage message



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
# File 'lib/rgovdata/shell/shell.rb', line 9

def self.usage
  puts <<-EOS

rgovdata client v#{RGovData::Version::STRING}
===================================

Usage:
rgd [options]

Command Options
-c | --command    immediately executes the command provided

The following commands are supported in the rgovdata shell.
They can also be passed on the command line:

rgd -c command

== Core Commands ==
help
exit
show status

== Discovery Commands ==
ls
cd
info

  EOS
end

Instance Method Details

#runObject

run the basic REPL



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rgovdata/shell/shell.rb', line 47

def run
  if options[:command].present?
    evaluate options[:command].join(' ')
    return
  end
  welcome
  repl = lambda do |prompt|
    print prompt
    evaluate( STDIN.gets.chomp! )
  end
  loop { break unless repl[prompt] }
end