Module: Bcome::Functions
- Included in:
- Stack::Environment, Stack::Instance
- Defined in:
- lib/functions.rb
Constant Summary collapse
- CONFIGS_PATH =
"bcome/config"
Instance Method Summary collapse
- #cmd_config_path ⇒ Object
- #cmd_for_ref(reference) ⇒ Object
- #cmd_functions ⇒ Object
- #F(reference) ⇒ Object
- #functions ⇒ Object
- #has_cmd_functions? ⇒ Boolean
- #has_functions_config? ⇒ Boolean
- #load_cmd_functions ⇒ Object
Instance Method Details
#cmd_config_path ⇒ Object
61 62 63 |
# File 'lib/functions.rb', line 61 def cmd_config_path "#{CONFIGS_PATH}/functions.yml" end |
#cmd_for_ref(reference) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/functions.rb', line 33 def cmd_for_ref(reference) commands = cmd_functions.select{|command| command[:ref].to_s == reference.to_s } raise "Multiple commands found for reference '#{reference}'. Your functions list is ambiguous.".failure if commands.size > 1 unless commands.any? puts "No command found for reference '#{reference}'".failure return nil end return commands.first end |
#cmd_functions ⇒ Object
43 44 45 46 |
# File 'lib/functions.rb', line 43 def cmd_functions return unless has_functions_config? @cmd_functions ||= load_cmd_functions end |
#F(reference) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/functions.rb', line 21 def F(reference) if self.is_a?(Bcome::Stack::Environment) && no_selections? puts "\n\n" + "You are an an Environment level, and have not selected any nodes to workon.".warning + "\n\n" else command = cmd_for_ref(reference) if command #puts "#{"Executing command '#{command[:ref]}': ".informational} > #{command[:command].command}" puts run command[:command] end end end |
#functions ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/functions.rb', line 5 def functions unless cmd_functions puts "\n\n" + "You don't yet have any custom functions defined. Have a read of the docs and define some. They're pretty useful.".warning + "\n\n" else puts "\n\n\s\s" + "Functions". + "\n\n" cmd_functions.each_with_index do |cmd_function, i| puts "\tShortcut: ". + "\s#{cmd_function[:ref].informational}" puts "\tDescription:". + "\s#{cmd_function[:description]}" puts "\tCommand:". + "\s#{cmd_function[:command]}" puts "\tUsage:". + "\sF \"#{cmd_function[:ref]}\"" puts end end return end |
#has_cmd_functions? ⇒ Boolean
48 49 50 |
# File 'lib/functions.rb', line 48 def has_cmd_functions? !cmd_functions.nil? end |
#has_functions_config? ⇒ Boolean
65 66 67 |
# File 'lib/functions.rb', line 65 def has_functions_config? File.exist?(cmd_config_path) end |
#load_cmd_functions ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/functions.rb', line 52 def load_cmd_functions configs = YAML.load_file(cmd_config_path) unless configs.has_key?(:single_functions) raise "Invalid functions configuration. Please check your yaml".failure else return configs[:single_functions] end end |