Module: SfCli::Console::Commands

Defined in:
lib/sf_cli/console/commands.rb

Overview

Developer Console commands

Instance Method Summary collapse

Instance Method Details

#apex(apex_code = nil) ⇒ Object



47
48
49
50
51
# File 'lib/sf_cli/console/commands.rb', line 47

def apex(apex_code = nil)
  return sf.apex.run target_org: target_org if apex_code.nil?

  sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
end

#available_modelsObject



29
30
31
# File 'lib/sf_cli/console/commands.rb', line 29

def available_models
  @available_models ||= []
end

#connectionObject Also known as: conn



39
40
41
# File 'lib/sf_cli/console/commands.rb', line 39

def connection
  SfCli::Sf::Model.connection
end

#generate(*object_types) ⇒ Object Also known as: gen



33
34
35
36
37
# File 'lib/sf_cli/console/commands.rb', line 33

def generate(*object_types)
  SfCli::Sf::Model.generate object_types
  available_models.append(*object_types).flatten
  object_types
end

#helpObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sf_cli/console/commands.rb', line 69

def help
  conf.inspect_mode = false
  puts <<~HELP
    Available commands:
      use   --- set current org.
      gen   --- generate Object model classes
      query --- Query by SOQL with human readable format
      apex  --- run Apex code
      conn  --- show current connection setting
      orgs  --- show the list of org

    Syntax:
      [use]
        use target-org

        parameters:
          targat-org --- Username or alias of the org you are going to use. If you are not sure about them, check by `sf org list`.

        example:
          use :your_org_alias

      [gen]
        gen object-name, object-name, ...
        generate object-name, object-name, ...

        parameters:
          object-name --- Comma separated Names. Symbol or String can be OK. At least 1 object name is required.

        example:
          gen :Account, :Contact, :User

      [query]
        query SOQL

          parameters:
            SOQL --- soql.You must quote it like "SELECT ...."

        example:
          query "SELECT Id, Name FROM Account LIMIT 3"

      [apex]
        apex apex_code

        parameters:
          apex code --- Apex code you want to execute.You must quote the code.

        example:
          apex "System.debug('abc');"

      [conn]
          conn
          connection

      [orgs]
          orgs
  HELP
  conf.inspect_mode = true
end

#orgsObject



60
61
62
63
64
# File 'lib/sf_cli/console/commands.rb', line 60

def orgs
  conf.inspect_mode = false
  system 'sf org list'
  conf.inspect_mode = true
end

#query(_soql) ⇒ Object



53
54
55
56
57
58
# File 'lib/sf_cli/console/commands.rb', line 53

def query(_soql)
  soql = _soql.is_a?(SfCli::Sf::Model::QueryMethods::QueryCondition) ? _soql.to_soql : _soql
  conf.inspect_mode = false
  puts sf.data.query(soql, format: :human, target_org: target_org)
  conf.inspect_mode = true
end

#target_orgObject



43
44
45
# File 'lib/sf_cli/console/commands.rb', line 43

def target_org
  connection.target_org
end

#use(target_org) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sf_cli/console/commands.rb', line 15

def use(target_org)
  org_info = sf.org.display target_org: target_org
  conn = SfCli::Sf::Model::SfCommandConnection.new target_org: target_org, instance_url: org_info.instance_url
  conn.open unless org_info.connected?

  SfCli::Sf::Model.set_connection conn

  available_models.each do |model|
    Object.const_get(model).connection = conn
  end

  true
end