Class: CMDB::Shell::DSL
- Inherits:
- BasicObject
- Defined in:
- lib/cmdb/shell/dsl.rb
Overview
Host for CMDB command methods. Every public method of this class is a CMDB command and its parameters represent the arguments to the command. If a command is successful, it always updates the ‘_` attribute with the output (return value) of the command.
Instance Method Summary collapse
- #cd(path) ⇒ Object (also: #chdir)
- #class ⇒ Object
- #get(key) ⇒ Object (also: #cat)
- #help ⇒ Object
-
#initialize(shell, out) ⇒ DSL
constructor
A new instance of DSL.
- #ls(path = '') ⇒ Object
- #pry ⇒ Object
- #quit ⇒ Object (also: #exit)
- #set(key, value) ⇒ Object
- #unset(key) ⇒ Object (also: #rm)
Constructor Details
#initialize(shell, out) ⇒ DSL
Returns a new instance of DSL.
7 8 9 10 11 |
# File 'lib/cmdb/shell/dsl.rb', line 7 def initialize(shell, out) @shell = shell @cmdb = @shell.cmdb @out = out end |
Instance Method Details
#cd(path) ⇒ Object Also known as: chdir
63 64 65 66 67 |
# File 'lib/cmdb/shell/dsl.rb', line 63 def cd(path) pwd = @shell.(path) @shell.pwd = ::CMDB.split(pwd) pwd.to_sym end |
#class ⇒ Object
13 14 15 |
# File 'lib/cmdb/shell/dsl.rb', line 13 def class DSL end |
#get(key) ⇒ Object Also known as: cat
40 41 42 43 44 |
# File 'lib/cmdb/shell/dsl.rb', line 40 def get(key) key = @shell.(key) @cmdb.get(key) end |
#help ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cmdb/shell/dsl.rb', line 22 def help @out.info 'Commands:' @out.info ' cd <key> - append/remove search prefix' @out.info ' cd / - reset search prefix' @out.info ' get <key> - print value of key' @out.info ' ls - show keys and values' @out.info ' set <key> <value> - print value of key' @out.info ' quit - exit the shell' @out.info 'Key notation:' @out.info ' a.b.c - relative to search prefix' @out.info ' ../b/c - relative to parent of search prefix' @out.info ' /a - relative to root (i.e. all sources)' @out.info 'Shortcuts:' @out.info ' <key> - for get' @out.info ' <key>=<value> - for set' @out.info ' cat,rm,unset,... - as expected' end |
#ls(path = '') ⇒ Object
17 18 19 20 |
# File 'lib/cmdb/shell/dsl.rb', line 17 def ls(path='') prefix = @shell.(path) @cmdb.search prefix end |
#pry ⇒ Object
70 71 72 |
# File 'lib/cmdb/shell/dsl.rb', line 70 def pry end |
#quit ⇒ Object Also known as: exit
74 75 76 |
# File 'lib/cmdb/shell/dsl.rb', line 74 def quit ::Kernel.raise ::Interrupt end |
#set(key, value) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/cmdb/shell/dsl.rb', line 47 def set(key, value) key = @shell. key if @cmdb.set(key, value) @cmdb.get(key) else ::Kernel.raise ::CMDB::BadCommand.new('set', "No source accepts writes for '#{::CMDB.split(key).first}'") end end |
#unset(key) ⇒ Object Also known as: rm
57 58 59 60 |
# File 'lib/cmdb/shell/dsl.rb', line 57 def unset(key) @cmdb.set(key, nil) @cmdb.get(key) end |