Class: Mushy::Bash

Inherits:
Flux
  • Object
show all
Defined in:
lib/mushy/fluxs/bash.rb

Direct Known Subclasses

GitLog, Ls, Pwd, SimplePythonProgram, TwilioMessage

Instance Attribute Summary

Attributes inherited from Flux

#config, #flow, #id, #masher, #parent_fluxs, #subscribed_to, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Flux

#convert_this_to_an_array, #convert_to_symbolized_hash, #execute, #execute_single_event, #group_these_results, #guard, #ignore_these_results, inherited, #initialize, #join_these_results, #limit_these_results, #merge_these_results, #model_these_results, #outgoing_split_these_results, #shape_these, #sort_these_results, #standardize_these

Constructor Details

This class inherits a constructor from Mushy::Flux

Class Method Details

.detailsObject



2
3
4
5
6
7
8
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
38
39
40
41
42
# File 'lib/mushy/fluxs/bash.rb', line 2

def self.details
  {
    name: 'Bash',
    title: 'Execute a command via bash',
    description: 'Run a bash command.',
    fluxGroup: { name: 'Execute' },
    config: {
      command: {
        description: 'The command to run in bash.',
        type: 'text',
        value: '{{command}}'
      },
      directory: {
        description: 'The working directory in which the command will be run.',
        type: 'text',
        shrink: true,
        value: ''
      }
    },
    examples: {
      'Successful Call' => {
        description: 'This will run the ls command and return the full bash result.',
        input: { command: 'ls' },
        result: {
          text: "bin\nblue_heart.png\nthe_output.txt\n",
          success: true,
          exit_code: 0
        }
      },
      'Failed Call' => {
        description: 'This is an example of what happens when the command fails.',
        input: { command: 'rm file_that_does_not_exist.txt' },
        result: {
          text: '',
          success: false,
          exit_code: 256
        }
      }
    }
  }
end

Instance Method Details

#process(_, config) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mushy/fluxs/bash.rb', line 44

def process(_, config)
  command = config[:command]

  command = "cd #{config[:directory]};#{command}" if config[:directory]

  text = `#{command}`

  result = $?
  {
    text: text,
    success: result.success?,
    exit_code: result.to_i
  }
end