sf_cli 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -2
- data/README.rdoc +85 -40
- data/lib/sf_cli/sf/core/base.rb +2 -0
- data/lib/sf_cli/sf/data/bulk_result_v2.rb +77 -0
- data/lib/sf_cli/sf/data/core.rb +22 -162
- data/lib/sf_cli/sf/data/create_record.rb +30 -0
- data/lib/sf_cli/sf/data/delete_bulk.rb +47 -0
- data/lib/sf_cli/sf/data/delete_record.rb +33 -0
- data/lib/sf_cli/sf/data/delete_resume.rb +47 -0
- data/lib/sf_cli/sf/data/get_record.rb +42 -0
- data/lib/sf_cli/sf/data/helper_methods.rb +12 -0
- data/lib/sf_cli/sf/data/query.rb +120 -0
- data/lib/sf_cli/sf/data/query_helper.rb +57 -0
- data/lib/sf_cli/sf/data/resume.rb +87 -0
- data/lib/sf_cli/sf/data/search.rb +50 -0
- data/lib/sf_cli/sf/data/update_record.rb +38 -0
- data/lib/sf_cli/sf/data/upsert_bulk.rb +50 -0
- data/lib/sf_cli/sf/data/upsert_resume.rb +47 -0
- data/lib/sf_cli/sf/model/base_methods.rb +62 -0
- data/lib/sf_cli/sf/model/class_definition.rb +34 -43
- data/lib/sf_cli/sf/model/dml_methods.rb +36 -0
- data/lib/sf_cli/sf/model/generator.rb +8 -7
- data/lib/sf_cli/sf/model/query_condition.rb +136 -0
- data/lib/sf_cli/sf/model/query_methods.rb +58 -0
- data/lib/sf_cli/sf/model/sf_command_connection.rb +60 -0
- data/lib/sf_cli/sf/model.rb +10 -2
- data/lib/sf_cli/sf/org/core.rb +6 -44
- data/lib/sf_cli/sf/org/display.rb +41 -0
- data/lib/sf_cli/sf/org/list.rb +67 -0
- data/lib/sf_cli/sf/org/login.rb +64 -0
- data/lib/sf_cli/sf/project/core.rb +10 -3
- data/lib/sf_cli/sf/sobject/core.rb +15 -5
- data/lib/sf_cli/sf/sobject/schema.rb +47 -0
- data/lib/sf_cli.rb +8 -5
- metadata +29 -8
- data/lib/sf_cli/sf/model/schema.rb +0 -33
@@ -0,0 +1,36 @@
|
|
1
|
+
module SfCli
|
2
|
+
module Sf
|
3
|
+
module Model
|
4
|
+
module DmlMethods
|
5
|
+
def self.included(c)
|
6
|
+
c.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
def save
|
10
|
+
if new_record?
|
11
|
+
self.Id = self.class.connection.create(self.class.name.to_sym, current_attributes.reject{|_,v| v.nil?})
|
12
|
+
else
|
13
|
+
self.class.connection.update(self.class.name.to_sym, self.Id, updated_attributes.reject{|_,v| v.nil?})
|
14
|
+
end
|
15
|
+
|
16
|
+
@original_attributes = current_attributes.dup
|
17
|
+
@updated_attributes = {}
|
18
|
+
|
19
|
+
self.Id
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
return if self.Id.nil?
|
24
|
+
|
25
|
+
self.class.connection.delete(self.class.name.to_sym, self.Id)
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def create(values = {})
|
30
|
+
connection.create(name.to_sym, values, Object.const_get(name.to_sym))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,25 +1,26 @@
|
|
1
|
-
require_relative '../sobject/core'
|
2
1
|
require_relative './class_definition'
|
3
2
|
|
4
3
|
module SfCli
|
5
4
|
module Sf
|
6
5
|
module Model
|
7
6
|
class Generator
|
8
|
-
attr_reader :sf_sobject, :
|
7
|
+
attr_reader :sf_sobject, :connection
|
9
8
|
|
10
|
-
def initialize(
|
11
|
-
@
|
12
|
-
@target_org = target_org
|
9
|
+
def initialize(connection)
|
10
|
+
@connection = connection
|
13
11
|
end
|
14
12
|
|
15
13
|
def generate(object_name)
|
16
|
-
|
14
|
+
schema = describe(object_name)
|
15
|
+
class_definition = ClassDefinition.new(schema)
|
17
16
|
|
18
17
|
instance_eval "::#{object_name} = #{class_definition}"
|
18
|
+
klass = Object.const_get object_name.to_sym
|
19
|
+
klass.connection = connection
|
19
20
|
end
|
20
21
|
|
21
22
|
def describe(object_name)
|
22
|
-
|
23
|
+
connection.describe object_name
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
module Sf
|
5
|
+
module Model
|
6
|
+
module QueryMethods
|
7
|
+
class QueryCondition
|
8
|
+
attr_reader :connection, :object_name, :all_field_names, :fields, :conditions, :limit_num, :row_order
|
9
|
+
|
10
|
+
def initialize(connection, object_name, field_names)
|
11
|
+
@object_name = object_name
|
12
|
+
@all_field_names = field_names
|
13
|
+
@connection = connection
|
14
|
+
@fields = []
|
15
|
+
@conditions = []
|
16
|
+
@limit_num = nil
|
17
|
+
@row_order = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def where(*expr)
|
21
|
+
return self if expr&.empty?
|
22
|
+
return self if expr.map{|o| (o == '' || o == {} || o == []) ? nil : o}.compact.size.zero?
|
23
|
+
return self unless [Hash, Symbol, String].any?{|klass| expr.first.instance_of? klass}
|
24
|
+
|
25
|
+
if expr.size > 1
|
26
|
+
return self if expr.size < 3
|
27
|
+
|
28
|
+
value = case expr[2].class.name.to_sym
|
29
|
+
when :String
|
30
|
+
%|'#{expr[2]}'|
|
31
|
+
when :Time
|
32
|
+
expr[2].to_datetime
|
33
|
+
when :Array
|
34
|
+
candidates = expr[2].map do |o|
|
35
|
+
case o.class.name.to_sym
|
36
|
+
when :String
|
37
|
+
%|'#{o}'|
|
38
|
+
when :Time
|
39
|
+
o.to_datetime
|
40
|
+
else
|
41
|
+
o
|
42
|
+
end
|
43
|
+
end
|
44
|
+
%|IN (#{candidates.join(', ')})|
|
45
|
+
else
|
46
|
+
expr[2]
|
47
|
+
end
|
48
|
+
conditions << %|#{expr[0]} #{expr[1]} #{value}|
|
49
|
+
|
50
|
+
return self
|
51
|
+
end
|
52
|
+
|
53
|
+
if expr[0].instance_of? String
|
54
|
+
conditions << expr[0]
|
55
|
+
return self
|
56
|
+
end
|
57
|
+
|
58
|
+
new_conditions =
|
59
|
+
expr[0].map do |k,v|
|
60
|
+
case v.class.name.to_sym
|
61
|
+
when :String
|
62
|
+
%|#{k} = '#{v}'|
|
63
|
+
when :Time
|
64
|
+
%|#{k} = #{v.to_datetime}|
|
65
|
+
when :Array
|
66
|
+
candidates = v.map do |o|
|
67
|
+
case o.class.name.to_sym
|
68
|
+
when :String
|
69
|
+
%|'#{o}'|
|
70
|
+
when :Time
|
71
|
+
%|#{o.to_datetime}|
|
72
|
+
else
|
73
|
+
o
|
74
|
+
end
|
75
|
+
end
|
76
|
+
%|#{k} IN (#{candidates.join(', ')})|
|
77
|
+
else
|
78
|
+
"#{k} = #{v}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
conditions.append new_conditions
|
82
|
+
return self
|
83
|
+
end
|
84
|
+
|
85
|
+
def select(*expr)
|
86
|
+
return self if expr&.empty?
|
87
|
+
|
88
|
+
if expr.size > 1
|
89
|
+
@fields = self.fields + expr
|
90
|
+
else
|
91
|
+
self.fields << expr.first
|
92
|
+
end
|
93
|
+
return self
|
94
|
+
end
|
95
|
+
|
96
|
+
def limit(num)
|
97
|
+
@limit_num = num
|
98
|
+
return self
|
99
|
+
end
|
100
|
+
|
101
|
+
def order(*fields)
|
102
|
+
return self if fields&.empty?
|
103
|
+
|
104
|
+
@row_order = fields
|
105
|
+
return self
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_soql
|
109
|
+
base = 'SELECT %{select} FROM %{object}' % {select: select_fields, object: object_name}
|
110
|
+
where = conditions.size.zero? ? nil : 'WHERE %{where}' % {where: conditions.flatten.join(' AND ')}
|
111
|
+
_order = row_order.nil? ? nil : 'ORDER BY %{order}' % {order: row_order.join(', ')}
|
112
|
+
limit = limit_num.nil? ? nil : 'LIMIT %{limit}' % {limit: limit_num}
|
113
|
+
|
114
|
+
[base, where, _order, limit].compact.join(' ')
|
115
|
+
end
|
116
|
+
|
117
|
+
def all
|
118
|
+
connection.query(to_soql, Object.const_get(object_name.to_sym))
|
119
|
+
end
|
120
|
+
|
121
|
+
def pluck(field_name)
|
122
|
+
all.map{|record| record.__send__(field_name.to_sym)}
|
123
|
+
end
|
124
|
+
|
125
|
+
def take
|
126
|
+
all.first
|
127
|
+
end
|
128
|
+
|
129
|
+
def select_fields
|
130
|
+
(fields.empty? ? all_field_names : fields).join(', ')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative './query_condition'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
module Sf
|
5
|
+
module Model
|
6
|
+
module QueryMethods
|
7
|
+
def self.included(c)
|
8
|
+
c.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def where(*expr)
|
13
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
14
|
+
qc.where(*expr)
|
15
|
+
return qc
|
16
|
+
end
|
17
|
+
|
18
|
+
def select(*fields)
|
19
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
20
|
+
qc.select(*fields)
|
21
|
+
return qc
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(id)
|
25
|
+
connection.find(name.to_sym, id, Object.const_get(name.to_sym))
|
26
|
+
end
|
27
|
+
|
28
|
+
def limit(num)
|
29
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
30
|
+
qc.limit(num)
|
31
|
+
qc
|
32
|
+
end
|
33
|
+
|
34
|
+
def order(*field_names)
|
35
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
36
|
+
qc.order(*field_names)
|
37
|
+
qc
|
38
|
+
end
|
39
|
+
|
40
|
+
def all
|
41
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
42
|
+
qc.all
|
43
|
+
end
|
44
|
+
|
45
|
+
def pluck(field_name)
|
46
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
47
|
+
qc.pluck(field_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def take
|
51
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
52
|
+
qc.take
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../sobject/core'
|
2
|
+
require_relative '../data/core'
|
3
|
+
require_relative '../org/core'
|
4
|
+
|
5
|
+
module SfCli
|
6
|
+
module Sf
|
7
|
+
module Model
|
8
|
+
class SfCommandConnection
|
9
|
+
attr_reader :sf_data, :sf_org, :sf_sobject, :target_org, :instance_url
|
10
|
+
|
11
|
+
def initialize(target_org: nil, instance_url: nil)
|
12
|
+
@sf_org = ::SfCli::Sf::Org::Core.new
|
13
|
+
@sf_data = ::SfCli::Sf::Data::Core.new
|
14
|
+
@sf_sobject = ::SfCli::Sf::Sobject::Core.new
|
15
|
+
@target_org = target_org
|
16
|
+
@instance_url = instance_url
|
17
|
+
end
|
18
|
+
|
19
|
+
def open
|
20
|
+
if ENV['SF_ACCESS_TOKEN']
|
21
|
+
sf_org.login_access_token target_org: target_org, instance_url: instance_url
|
22
|
+
else
|
23
|
+
sf_org.login_web target_org: target_org, instance_url: instance_url
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(object_type, id, klass)
|
28
|
+
sf_data.get_record object_type, record_id: id, target_org: target_org, model_class: klass
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(object_type, values, klass = nil)
|
32
|
+
id = sf_data.create_record object_type, values: values, target_org: target_org
|
33
|
+
return id if klass.nil?
|
34
|
+
|
35
|
+
find(object_type, id, klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
def update(object_type, id, values)
|
39
|
+
sf_data.update_record object_type, record_id: id, where: nil, values: values, target_org: target_org
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(object_type, id)
|
43
|
+
sf_data.delete_record object_type, record_id: id, where: nil, target_org: target_org
|
44
|
+
end
|
45
|
+
|
46
|
+
def query(soql, klass)
|
47
|
+
sf_data.query soql, target_org: target_org, model_class: klass
|
48
|
+
end
|
49
|
+
|
50
|
+
def exec_query(soql, format: nil, bulk: false, timeout: nil, model_class: nil)
|
51
|
+
sf_data.query(soql, target_org: target_org, format: format, bulk: bulk, timeout: timeout, model_class: model_class)
|
52
|
+
end
|
53
|
+
|
54
|
+
def describe(object_type)
|
55
|
+
sf_sobject.describe(object_type, target_org: target_org)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/sf_cli/sf/model.rb
CHANGED
@@ -9,8 +9,16 @@ module SfCli
|
|
9
9
|
# see the section {"Object Model support"}[link://files/README_rdoc.html#label-Object+Model+support+-28experimental-2C+since+0.0.4-29] in README.
|
10
10
|
#
|
11
11
|
module Model
|
12
|
-
def self.
|
13
|
-
|
12
|
+
def self.connection
|
13
|
+
@@connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.set_connection(conn)
|
17
|
+
@@connection = conn
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.generate(object_names)
|
21
|
+
generator = Generator.new(connection)
|
14
22
|
|
15
23
|
object_names.each do |object_name|
|
16
24
|
generator.generate(object_name)
|
data/lib/sf_cli/sf/org/core.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require_relative '../core/base'
|
2
|
+
require_relative './login'
|
3
|
+
require_relative './display'
|
4
|
+
require_relative './list'
|
2
5
|
|
3
6
|
module SfCli
|
4
7
|
module Sf
|
@@ -11,50 +14,9 @@ module SfCli
|
|
11
14
|
#
|
12
15
|
class Core
|
13
16
|
include ::SfCli::Sf::Core::Base
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# login to the org by the browser. (equivalent to *sf* *org* *login* *web*)
|
18
|
-
#
|
19
|
-
# *target_org* --- an alias of paticular org, not default one<br>
|
20
|
-
# *instance_url* --- custom login url.
|
21
|
-
#
|
22
|
-
# == examples:
|
23
|
-
# sf.org.login_web
|
24
|
-
# sf.org.login_web target_org: :dev # if the org you login isn't the default one, you should give it alias name for later use.
|
25
|
-
#
|
26
|
-
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_web_unified]
|
27
|
-
#
|
28
|
-
def login_web(target_org: nil, instance_url: nil)
|
29
|
-
flags = {
|
30
|
-
:"alias" => target_org,
|
31
|
-
:"instance-url" => instance_url,
|
32
|
-
}
|
33
|
-
action = __method__.to_s.tr('_', ' ')
|
34
|
-
exec(action, flags: flags)
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# returns the org's connection information. (equivalent to *sf* *org* *display*)
|
39
|
-
#
|
40
|
-
# *target_org* --- an alias of paticular org, not default one<br>
|
41
|
-
#
|
42
|
-
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_display_unified]
|
43
|
-
#
|
44
|
-
def display(target_org: nil)
|
45
|
-
flags = {:"target-org" => target_org}
|
46
|
-
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
47
|
-
|
48
|
-
ConnectionInfo.new(
|
49
|
-
id: json['result']['id'],
|
50
|
-
access_token: json['result']['accessToken'],
|
51
|
-
alias: json['result']['alias'],
|
52
|
-
instance_url: json['result']['instanceUrl'],
|
53
|
-
user_name: json['result']['username'],
|
54
|
-
api_version: json['result']['apiVersion'],
|
55
|
-
status: json['result']['connectedStatus']
|
56
|
-
)
|
57
|
-
end
|
17
|
+
include Login
|
18
|
+
include Display
|
19
|
+
include List
|
58
20
|
end
|
59
21
|
end
|
60
22
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SfCli::Sf::Org
|
2
|
+
module Display
|
3
|
+
ConnectionInfo = Struct.new(:id, :access_token, :alias, :instance_url, :user_name, :api_version, :status)
|
4
|
+
|
5
|
+
#
|
6
|
+
# returns the org's connection information. (equivalent to *sf* *org* *display*)
|
7
|
+
#
|
8
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
9
|
+
#
|
10
|
+
# ======
|
11
|
+
# # example (in irb):
|
12
|
+
#
|
13
|
+
# > sf.org.display
|
14
|
+
# =>
|
15
|
+
# #<struct SfCli::Sf::Org::Display::ConnectionInfo
|
16
|
+
# id="00D5j00000DiuxmEAB",
|
17
|
+
# access_token="<some access token>",
|
18
|
+
# alias="dev",
|
19
|
+
# instance_url="https://hoge-bar-baz.abc.my.salesforce.com.example",
|
20
|
+
# user_name="user@example.sandbox",
|
21
|
+
# api_version="61.0",
|
22
|
+
# status="Connected">
|
23
|
+
#
|
24
|
+
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_display_unified]
|
25
|
+
#
|
26
|
+
def display(target_org: nil)
|
27
|
+
flags = {:"target-org" => target_org}
|
28
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
29
|
+
|
30
|
+
ConnectionInfo.new(
|
31
|
+
id: json['result']['id'],
|
32
|
+
access_token: json['result']['accessToken'],
|
33
|
+
alias: json['result']['alias'],
|
34
|
+
instance_url: json['result']['instanceUrl'],
|
35
|
+
user_name: json['result']['username'],
|
36
|
+
api_version: json['result']['apiVersion'],
|
37
|
+
status: json['result']['connectedStatus']
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module SfCli::Sf::Org
|
2
|
+
module List
|
3
|
+
OrgConfig = Struct.new( :accessToken, :instanceUrl, :orgId, :username, :loginUrl,
|
4
|
+
:clientId, :isDevHub, :instanceApiVersion, :instanceApiVersionLastRetrieved, :name,
|
5
|
+
:instanceName, :namespacePrefix, :isSandbox, :isScratch, :trailExpirationDate, :tracksSource,
|
6
|
+
:alias, :isDefaultDevHubUsername, :isDefaultUsername, :lastUsed, :connectedStatus) do
|
7
|
+
def devhub?
|
8
|
+
isDevHub
|
9
|
+
end
|
10
|
+
|
11
|
+
def sandbox?
|
12
|
+
isSandbox
|
13
|
+
end
|
14
|
+
|
15
|
+
def scratch?
|
16
|
+
isScratch
|
17
|
+
end
|
18
|
+
|
19
|
+
def default?
|
20
|
+
isDefaultUsername
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_devhub?
|
24
|
+
isDefaultDevHubUsername
|
25
|
+
end
|
26
|
+
|
27
|
+
def connected?
|
28
|
+
connectedStatus == 'Connected'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# \List orgs you’ve created or authenticated to
|
33
|
+
#
|
34
|
+
# ======
|
35
|
+
# org_config_list = sf.org.list # returns a list of OrgConfig
|
36
|
+
#
|
37
|
+
# \OrgConfig object has a org information including security sensitive things such as access token, username and so on.
|
38
|
+
#
|
39
|
+
# It also has some methods to identify its org type:
|
40
|
+
# - devhub?
|
41
|
+
# - sandbox?
|
42
|
+
# - scratch?
|
43
|
+
# - default?
|
44
|
+
# - default_devhub?
|
45
|
+
#
|
46
|
+
# and you can check the org connected like this:
|
47
|
+
# org_config_list = sf.org.list # returns a list of OrgConfig
|
48
|
+
# org_config.first.conncected?
|
49
|
+
#
|
50
|
+
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_list_unified]
|
51
|
+
#
|
52
|
+
def list
|
53
|
+
flags = {
|
54
|
+
# reserved for later option addition
|
55
|
+
}
|
56
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
57
|
+
|
58
|
+
others = json['result']['other'].map{|config| OrgConfig.new(**config)}
|
59
|
+
sandboxes = json['result']['sandboxes'].map{|config| OrgConfig.new(**config)}
|
60
|
+
non_scratch_orgs = json['result']['nonScratchOrgs'].map{|config| OrgConfig.new(**config)}
|
61
|
+
devhubs = json['result']['devHubs'].map{|config| OrgConfig.new(**config)}
|
62
|
+
scratch_orgs = json['result']['scratchOrgs'].map{|config| OrgConfig.new(**config)}
|
63
|
+
|
64
|
+
(others + sandboxes + non_scratch_orgs + devhubs + scratch_orgs).uniq{|config| config.alias}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module SfCli::Sf::Org
|
2
|
+
module Login
|
3
|
+
# login to the org by the browser.
|
4
|
+
#
|
5
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
6
|
+
#
|
7
|
+
# *instance_url* --- URL of the instance that the org lives on.
|
8
|
+
#
|
9
|
+
# *browser* --- browser in which to open the org.
|
10
|
+
#
|
11
|
+
# == examples:
|
12
|
+
# sf.org.login_web
|
13
|
+
# sf.org.login_web target_org: :dev
|
14
|
+
#
|
15
|
+
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_web_unified]
|
16
|
+
#
|
17
|
+
def login_web(target_org: nil, instance_url: nil, browser: nil)
|
18
|
+
flags = {
|
19
|
+
:"alias" => target_org,
|
20
|
+
:"instance-url" => instance_url,
|
21
|
+
:"browser" => browser,
|
22
|
+
}
|
23
|
+
action = __method__.to_s.tr('_', ' ')
|
24
|
+
exec(action, flags: flags)
|
25
|
+
end
|
26
|
+
|
27
|
+
# login to the org by access token.
|
28
|
+
#
|
29
|
+
# NOTE: this method doesn't support user interactive mode, so *SF_ACCESS_TOKEN* environment variable must be set before call this method.
|
30
|
+
#
|
31
|
+
# *instance_url* --- URL of the instance that the org lives on.
|
32
|
+
#
|
33
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
34
|
+
#
|
35
|
+
# ======
|
36
|
+
# ENV['SF_ACCESS_TOKEN'] = 'xxxxxxxxxx'
|
37
|
+
# sf.org.login_access_token instance_url: https://hoge.bar.baz.salesforce.com
|
38
|
+
#
|
39
|
+
# == how to set env variable outside of ruby
|
40
|
+
# In Unix/mac:
|
41
|
+
# $ SF_ACCESS_TOKEN='xxxxxxxxxx'
|
42
|
+
# $ ruby app_using_sfcli.rb
|
43
|
+
# or
|
44
|
+
# $ SF_ACCESS_TOKEN='xxxxxxxxxx' ruby app_using_sfcli.rb
|
45
|
+
#
|
46
|
+
# In Windows:
|
47
|
+
# $ set SF_ACCESS_TOKEN=xxxxxxxxxx
|
48
|
+
# $ ruby app_using_sfcli.rb
|
49
|
+
#
|
50
|
+
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_access-token_unified]
|
51
|
+
#
|
52
|
+
def login_access_token(instance_url:, target_org: nil)
|
53
|
+
flags = {
|
54
|
+
:"instance-url" => instance_url,
|
55
|
+
:"alias" => target_org,
|
56
|
+
}
|
57
|
+
switches = {
|
58
|
+
:"no-prompt" => true,
|
59
|
+
}
|
60
|
+
action = __method__.to_s.tr('_', '-').sub('-', ' ')
|
61
|
+
exec action, flags: flags, switches: switches, redirection: :null_stderr
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -14,11 +14,14 @@ module SfCli
|
|
14
14
|
GenerateResult = Struct.new(:output_dir, :files, :raw_output, :warnings)
|
15
15
|
|
16
16
|
#
|
17
|
-
# generate a Salesforce project
|
17
|
+
# generate a Salesforce project
|
18
18
|
#
|
19
19
|
# *name* --- project name<br>
|
20
|
+
#
|
20
21
|
# *template* --- project template name<br>
|
22
|
+
#
|
21
23
|
# *output_dir* --- output directory<br>
|
24
|
+
#
|
22
25
|
# *manifest* --- switch to create manifest file in the project directory (manifest/package.xml). default: false
|
23
26
|
#
|
24
27
|
# For more command details, see the {reference document}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_generate_unified]
|
@@ -42,15 +45,19 @@ module SfCli
|
|
42
45
|
)
|
43
46
|
end
|
44
47
|
|
45
|
-
# generate the manifest file of a Salesforce project
|
48
|
+
# generate the manifest file of a Salesforce project
|
46
49
|
#
|
47
50
|
# *metadata* --- an array that consists of metadata type like CustomObject, Layout and so on. (default: [])<br>
|
51
|
+
#
|
48
52
|
# *api_verson* --- api version (default: nil)<br>
|
53
|
+
#
|
49
54
|
# *output_dir* --- manifest's output directory in the project directory. You can use relative path from the project root (default: nil)<br>
|
55
|
+
#
|
50
56
|
# *from_org* --- username or alias of the org that contains the metadata components from which to build a manifest (default: nil)<br>
|
57
|
+
#
|
51
58
|
# *source_dir* --- paths to the local source files to include in the manifest (default: nil)
|
52
59
|
#
|
53
|
-
#
|
60
|
+
# ======
|
54
61
|
# sf.project.generate_manifest metadata: %w[CustomObject Layout] # creates a package.xml, which is initialized with CustomObject and Layout
|
55
62
|
# sf.project.generate_manifest from_org: <org_name> # creates a package.xml, which is initialized with all metadata types in the org
|
56
63
|
#
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../core/base'
|
2
|
+
require_relative './schema'
|
2
3
|
|
3
4
|
module SfCli
|
4
5
|
module Sf
|
@@ -11,10 +12,18 @@ module SfCli
|
|
11
12
|
class Core
|
12
13
|
include ::SfCli::Sf::Core::Base
|
13
14
|
|
14
|
-
# returns a
|
15
|
+
# returns a schema object containing the Salesforce object schema
|
15
16
|
#
|
16
17
|
# *objectType* --- object type (ex: Account)<br>
|
17
|
-
#
|
18
|
+
#
|
19
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
20
|
+
#
|
21
|
+
# ======
|
22
|
+
# schema = sf.sobject.describe :Account
|
23
|
+
# schema.name # Account
|
24
|
+
# schema.label # Account
|
25
|
+
# schema.field_names # [:Id, :Name, ....]
|
26
|
+
# schema.fields[:Name] # => {"aggregatable"=>true, "aiPredictionField"=>false, "autoNumber"=>false,...}
|
18
27
|
#
|
19
28
|
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_describe_unified]
|
20
29
|
#
|
@@ -24,13 +33,14 @@ module SfCli
|
|
24
33
|
:"target-org" => target_org,
|
25
34
|
}
|
26
35
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
27
|
-
json['result']
|
36
|
+
Schema.new(json['result'])
|
28
37
|
end
|
29
38
|
|
30
|
-
# returns a list of Salesforce object
|
39
|
+
# returns a list of Salesforce object name
|
31
40
|
#
|
32
41
|
# *object_type* --- all or custom<br>
|
33
|
-
#
|
42
|
+
#
|
43
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
34
44
|
#
|
35
45
|
# For more command details, see {the command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm#cli_reference_sobject_list_unified]
|
36
46
|
#
|