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



45
46
47
48
49
# File 'lib/sf_cli/console/commands.rb', line 45

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



27
28
29
# File 'lib/sf_cli/console/commands.rb', line 27

def available_models
  @available_models ||= []
end

#connectionObject Also known as: conn



37
38
39
# File 'lib/sf_cli/console/commands.rb', line 37

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

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



31
32
33
34
35
# File 'lib/sf_cli/console/commands.rb', line 31

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

#helpObject



66
67
68
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
# File 'lib/sf_cli/console/commands.rb', line 66

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



57
58
59
60
61
# File 'lib/sf_cli/console/commands.rb', line 57

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

#query(soql) ⇒ Object



51
52
53
54
55
# File 'lib/sf_cli/console/commands.rb', line 51

def query(soql)
  conf.inspect_mode = false
  puts sf.data.query(soql, format: :human, target_org: target_org)
  conf.inspect_mode = true
end

#target_orgObject



41
42
43
# File 'lib/sf_cli/console/commands.rb', line 41

def target_org
  connection.target_org
end

#use(target_org) ⇒ Object



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

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