sf_cli 0.0.4 → 0.0.5
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 +18 -2
- data/README.rdoc +8 -32
- 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/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 +6 -4
- data/lib/sf_cli.rb +8 -5
- metadata +23 -7
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative './helper_methods'
|
2
|
+
require_relative './query_helper'
|
3
|
+
|
4
|
+
module SfCli::Sf::Data
|
5
|
+
module Query
|
6
|
+
# get object records using SOQL.
|
7
|
+
#
|
8
|
+
# *soql* --- SOQL<br>
|
9
|
+
#
|
10
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
11
|
+
#
|
12
|
+
# *format* --- get the command's raw output. human, csv, json can be available<br>
|
13
|
+
#
|
14
|
+
# *model_class* --- the object model class<br>
|
15
|
+
#
|
16
|
+
# *bulk* --- use Bulk API<br>
|
17
|
+
#
|
18
|
+
# *timeout* --- max minutes to wait for the job complete in Bulk API mode<br>
|
19
|
+
#
|
20
|
+
# ======
|
21
|
+
# sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
|
22
|
+
#
|
23
|
+
# Account = Struct.new(:Id, :Name)
|
24
|
+
# sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
|
25
|
+
#
|
26
|
+
# # child-parent relationship is supported
|
27
|
+
# sf.data.query 'SELECT Id, Name, Account.Name From Contact Limit 1' # [{Id: "abc", Name: "contact name", Account: {Name: "account name"}}]
|
28
|
+
#
|
29
|
+
# # parent-children relationship is supported
|
30
|
+
# sf.data.query 'SELECT Id, Name, (SELECT Name From Contacts) FROM Account Limit 1' # [{Id: "abc", Name: "account name", Contacts: [{Name: "contact name"}]}]
|
31
|
+
#
|
32
|
+
# When using Bulk API, you get the records when the query job completes within time limit.
|
33
|
+
# The method returns a tapple(an array), which changes its contents according to the job result.
|
34
|
+
#
|
35
|
+
# ======
|
36
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true # max wait 1 min to get result (default)
|
37
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 5 # max wait 5 min to get result
|
38
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 0 # returns immediately
|
39
|
+
#
|
40
|
+
# rows = result if done # if job is completed, the result is an array of record
|
41
|
+
# job_id = result unless done # if job hasn't completed or it has aborted, the result is the job ID
|
42
|
+
#
|
43
|
+
# 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_data_commands_unified.htm#cli_reference_data_query_unified]
|
44
|
+
#
|
45
|
+
# About querying with auto generated object model, see the section {"Object Model support"}[link://files/README_rdoc.html#label-Object+Model+support+-28experimental-2C+since+0.0.4-29] in README.
|
46
|
+
#
|
47
|
+
def query(soql, target_org: nil, format: nil, bulk: false, timeout: nil, model_class: nil)
|
48
|
+
flags = {
|
49
|
+
:"query" => %("#{soql}"),
|
50
|
+
:"target-org" => target_org,
|
51
|
+
:"result-format" => format,
|
52
|
+
:"wait" => (bulk ? timeout : nil),
|
53
|
+
}
|
54
|
+
switches = {
|
55
|
+
bulk: bulk,
|
56
|
+
}
|
57
|
+
raw_output = format ? true : false
|
58
|
+
format = format&.to_sym || :json
|
59
|
+
|
60
|
+
result = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr, raw_output: raw_output, format: format)
|
61
|
+
|
62
|
+
return_result(result, raw_output, bulk, model_class)
|
63
|
+
end
|
64
|
+
|
65
|
+
# resume a bulk query job, which you previously started, and get records
|
66
|
+
#
|
67
|
+
# *job_id* --- job ID you want to resume<br>
|
68
|
+
#
|
69
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
70
|
+
#
|
71
|
+
# *format* --- get the command's raw output. human, csv, json can be available<br>
|
72
|
+
#
|
73
|
+
# *model_class* --- the object model class<br>
|
74
|
+
#
|
75
|
+
# ======
|
76
|
+
# # start a query job
|
77
|
+
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, timeout: 0 # returns immediately
|
78
|
+
#
|
79
|
+
# result1 # => [false, "<job id>"]
|
80
|
+
#
|
81
|
+
# # the job has already started asynchronously.
|
82
|
+
# # So you should check and get the result.
|
83
|
+
# done, result2 = sf.data.query_resume job_id: result1.last
|
84
|
+
#
|
85
|
+
# puts 'get the records!' if done # the job has completed
|
86
|
+
#
|
87
|
+
# result2 # => if done is true, this is an array of record. Otherwise it should be the Job ID.
|
88
|
+
#
|
89
|
+
# 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_data_commands_unified.htm#cli_reference_data_query_resume_unified]
|
90
|
+
def query_resume(job_id:, target_org: nil, format: nil, model_class: nil)
|
91
|
+
flags = {
|
92
|
+
:"bulk-query-id" => job_id,
|
93
|
+
:"target-org" => target_org,
|
94
|
+
:"result-format" => format,
|
95
|
+
}
|
96
|
+
raw_output = format ? true : false
|
97
|
+
format = format || :json
|
98
|
+
|
99
|
+
action = __method__.to_s.tr('_', ' ')
|
100
|
+
result = exec(action, flags: flags, redirection: :null_stderr, raw_output: raw_output, format: format)
|
101
|
+
|
102
|
+
return_result(result, raw_output, true, model_class)
|
103
|
+
end
|
104
|
+
|
105
|
+
def return_result(result, raw_output, bulk, model_class)
|
106
|
+
result_adjuster =
|
107
|
+
if raw_output
|
108
|
+
RawOutputResultAdjuster.new(result)
|
109
|
+
elsif bulk
|
110
|
+
BulkResultAdjuster.new(result, model_class)
|
111
|
+
else
|
112
|
+
RegularResultAdjuster.new(result, model_class)
|
113
|
+
end
|
114
|
+
|
115
|
+
result_adjuster.get_return_value
|
116
|
+
end
|
117
|
+
|
118
|
+
private :return_result
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative './helper_methods'
|
2
|
+
|
3
|
+
module SfCli::Sf::Data
|
4
|
+
module Query
|
5
|
+
class RegularResultAdjuster # :nodoc: all
|
6
|
+
include ::SfCli::Sf::Data::HelperMethods
|
7
|
+
|
8
|
+
attr_reader :result, :model_class
|
9
|
+
|
10
|
+
def initialize(result, model_class)
|
11
|
+
@result = result
|
12
|
+
@model_class = model_class
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_return_value
|
16
|
+
result['result']['records'].each_with_object([]) do |h, a|
|
17
|
+
record = prepare_record(h)
|
18
|
+
a << (model_class ? model_class.new(**record) : record)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class BulkResultAdjuster # :nodoc: all
|
24
|
+
include ::SfCli::Sf::Data::HelperMethods
|
25
|
+
|
26
|
+
attr_reader :result, :model_class
|
27
|
+
|
28
|
+
def initialize(result, model_class)
|
29
|
+
@result = result
|
30
|
+
@model_class = model_class
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_return_value
|
34
|
+
done = result['result']['done']
|
35
|
+
id = result['result']['id']
|
36
|
+
rows = result['result']['records'].each_with_object([]) do |h, a|
|
37
|
+
record = prepare_record_in_bulk_mode(h)
|
38
|
+
a << (model_class ? model_class.new(**record) : record)
|
39
|
+
end
|
40
|
+
|
41
|
+
done ? [done, rows] : [done, id]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class RawOutputResultAdjuster # :nodoc: all
|
46
|
+
attr_reader :result
|
47
|
+
|
48
|
+
def initialize(result)
|
49
|
+
@result = result
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_return_value
|
53
|
+
result
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module SfCli::Sf::Data
|
2
|
+
module Resume
|
3
|
+
JobInfo = Struct.new(
|
4
|
+
:id,
|
5
|
+
:operation,
|
6
|
+
:object,
|
7
|
+
:createdById,
|
8
|
+
:createdDate,
|
9
|
+
:systemModstamp,
|
10
|
+
:state,
|
11
|
+
:concurrencyMode,
|
12
|
+
:contentType,
|
13
|
+
:numberBatchesQueued,
|
14
|
+
:numberBatchesInProgress,
|
15
|
+
:numberBatchesCompleted,
|
16
|
+
:numberBatchesFailed,
|
17
|
+
:numberBatchesTotal,
|
18
|
+
:numberRecordsProcessed,
|
19
|
+
:numberRetries,
|
20
|
+
:apiVersion,
|
21
|
+
:numberRecordsFailed,
|
22
|
+
:totalProcessingTime,
|
23
|
+
:apiActiveProcessingTime,
|
24
|
+
:apexProcessingTime
|
25
|
+
) do
|
26
|
+
def opened?
|
27
|
+
state == 'Open'
|
28
|
+
end
|
29
|
+
|
30
|
+
def upload_completed?
|
31
|
+
state == 'UploadComplete'
|
32
|
+
end
|
33
|
+
|
34
|
+
def in_progress?
|
35
|
+
state == 'InProgress'
|
36
|
+
end
|
37
|
+
|
38
|
+
def completed?
|
39
|
+
state == 'JobComplete'
|
40
|
+
end
|
41
|
+
|
42
|
+
def failed?
|
43
|
+
state == 'Failed'
|
44
|
+
end
|
45
|
+
|
46
|
+
def aborted?
|
47
|
+
state == 'Aborted'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# View the status of a bulk job.
|
52
|
+
#
|
53
|
+
# *job_id* --- job ID you want to resume<br>
|
54
|
+
#
|
55
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
56
|
+
#
|
57
|
+
# ======
|
58
|
+
# # start a delete job
|
59
|
+
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
60
|
+
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
61
|
+
#
|
62
|
+
# jobinfo2 = sf.data.resume job_id: jobinfo.id
|
63
|
+
#
|
64
|
+
# puts 'yey!' if job_info2.completed? # the job has completed
|
65
|
+
#
|
66
|
+
# The job info object has methods to check the job status:
|
67
|
+
# - opened?
|
68
|
+
# - upload_completed?
|
69
|
+
# - in_progress?
|
70
|
+
# - completed?
|
71
|
+
#
|
72
|
+
# To know job status more, take a look at {the bulk API developer guide}[https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/bulk_api_2_job_states.htm]
|
73
|
+
#
|
74
|
+
# 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_data_commands_unified.htm#cli_reference_data_resume_unified]
|
75
|
+
#
|
76
|
+
def resume(job_id:, target_org: nil)
|
77
|
+
flags = {
|
78
|
+
:"job-id" => job_id,
|
79
|
+
:"target-org" => target_org,
|
80
|
+
}
|
81
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
82
|
+
|
83
|
+
json['result'].delete '$'
|
84
|
+
JobInfo.new(**json['result'])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SfCli::Sf::Data
|
2
|
+
module Search
|
3
|
+
# search objects using SOSL.
|
4
|
+
#
|
5
|
+
# *sosl* --- SOSL<br>
|
6
|
+
#
|
7
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
8
|
+
#
|
9
|
+
# *format* --- get the command's raw output. human, csv, json can be available. *NOTE*: if you choose csv, csv files are downloaded in current directory<br>
|
10
|
+
#
|
11
|
+
# ======
|
12
|
+
# # example (in irb):
|
13
|
+
#
|
14
|
+
# > sf.data.search "FIND {TIM OR YOUNG OR OIL} IN Name Fields"
|
15
|
+
# =>
|
16
|
+
# {"Lead"=>["00Q5j00000WgEuDEAV"],
|
17
|
+
# "Account"=>["0015j00001U2XvNAAV", "0015j00001U2XvMAAV", "0015j00001U2XvJAAV"],
|
18
|
+
# "Contact"=>
|
19
|
+
# ["0035j00001HB84BAAT",
|
20
|
+
# "0035j00001HB84DAAT"],
|
21
|
+
# "Opportunity"=>
|
22
|
+
# ["0065j00001XHJLjAAP",
|
23
|
+
# "0065j00001XHJLTAA5",
|
24
|
+
# "0065j00001XHJLJAA5"],
|
25
|
+
# "User"=>["0055j00000CcL2bAAF", "0055j00000CcL1YAAV"]}
|
26
|
+
#
|
27
|
+
# 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_data_commands_unified.htm#cli_reference_data_search_unified]
|
28
|
+
#
|
29
|
+
def search(sosl, target_org: nil, format: nil)
|
30
|
+
flags = {
|
31
|
+
:"query" => %|"#{sosl}"|,
|
32
|
+
:"target-org" => target_org,
|
33
|
+
:"result-format" => format,
|
34
|
+
}
|
35
|
+
raw_output = format ? true : false
|
36
|
+
format = format&.to_sym || :json
|
37
|
+
|
38
|
+
result = exec(__method__, flags: flags, redirection: :null_stderr, raw_output: raw_output, format: format)
|
39
|
+
|
40
|
+
return if format == :csv
|
41
|
+
return result if format == :human
|
42
|
+
|
43
|
+
result['result']['searchRecords']
|
44
|
+
.group_by{|r| r['attributes']['type']}
|
45
|
+
.each_with_object({}) do |(object_type, records), result|
|
46
|
+
result[object_type] = records.map{|r| r['Id']}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SfCli::Sf::Data
|
2
|
+
module UpdateRecord
|
3
|
+
|
4
|
+
# update a object record.
|
5
|
+
#
|
6
|
+
# *object_type* --- \Object Type (ex. Account)<br>
|
7
|
+
#
|
8
|
+
# *record_id* --- id of the object<br>
|
9
|
+
#
|
10
|
+
# *where* --- field values that is used to identify a record<br>
|
11
|
+
#
|
12
|
+
# *values* --- field values for update<br>
|
13
|
+
#
|
14
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
15
|
+
#
|
16
|
+
# ==== examples
|
17
|
+
# sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
|
18
|
+
# sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
|
19
|
+
#
|
20
|
+
# 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_data_commands_unified.htm#cli_reference_data_update_record_unified]
|
21
|
+
#
|
22
|
+
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
|
23
|
+
where_conditions = field_value_pairs(where)
|
24
|
+
field_values = field_value_pairs(values)
|
25
|
+
flags = {
|
26
|
+
:"sobject" => object_type,
|
27
|
+
:"record-id" => record_id,
|
28
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
29
|
+
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
30
|
+
:"target-org" => target_org,
|
31
|
+
}
|
32
|
+
action = __method__.to_s.tr('_', ' ')
|
33
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
34
|
+
|
35
|
+
json['result']['id']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative './bulk_result_v2'
|
2
|
+
|
3
|
+
module SfCli::Sf::Data
|
4
|
+
module UpsertBulk
|
5
|
+
# update records using Bulk API 2.0
|
6
|
+
#
|
7
|
+
# *file* --- a \CSV file for update records<br>
|
8
|
+
#
|
9
|
+
# *sobject* --- \Object Type (ex. Account)<br>
|
10
|
+
#
|
11
|
+
# *external_id* --- Name of the external ID field, or the Id field<br>
|
12
|
+
#
|
13
|
+
# *timeout* --- max minutes to wait for the job complete the task.<br>
|
14
|
+
#
|
15
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
16
|
+
#
|
17
|
+
# ======
|
18
|
+
# # start a upsert job
|
19
|
+
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv' # this returns immediately
|
20
|
+
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
21
|
+
#
|
22
|
+
# # you can check if the upsert job completed
|
23
|
+
# sf.data.upsert_resume job_id: jobinfo.id
|
24
|
+
#
|
25
|
+
# # Or, you can wait for the job completion with one try.
|
26
|
+
# result = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', timeout: 5 # wait within 5 minutes
|
27
|
+
#
|
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_data_commands_unified.htm#cli_reference_data_upsert_bulk_unified]
|
29
|
+
#
|
30
|
+
def upsert_bulk(file:, sobject:, external_id:, timeout: nil, target_org: nil)
|
31
|
+
flags = {
|
32
|
+
:"file" => file,
|
33
|
+
:"sobject" => sobject,
|
34
|
+
:"external-id" => external_id,
|
35
|
+
:"wait" => timeout,
|
36
|
+
:"target-org" => target_org,
|
37
|
+
}
|
38
|
+
action = __method__.to_s.tr('_', ' ')
|
39
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
40
|
+
|
41
|
+
job_info = ::SfCli::Sf::Data::JobInfo.new(**json['result']['jobInfo'])
|
42
|
+
return job_info unless json['result']['records']
|
43
|
+
|
44
|
+
::SfCli::Sf::Data::BulkResultV2.new(
|
45
|
+
job_info: job_info,
|
46
|
+
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative './bulk_result_v2'
|
2
|
+
|
3
|
+
module SfCli::Sf::Data
|
4
|
+
module UpsertResume
|
5
|
+
# resume a bulk upsert job you previously started with Bulk API 2.0 and return a bulk result object.
|
6
|
+
#
|
7
|
+
# *job_id* --- job ID you want to resume<br>
|
8
|
+
#
|
9
|
+
# *timeout* --- max minutes to wait for the job complete the task.<br>
|
10
|
+
#
|
11
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
12
|
+
#
|
13
|
+
# ======
|
14
|
+
# # start a upsert job
|
15
|
+
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv' # this returns immediately
|
16
|
+
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
17
|
+
#
|
18
|
+
# # the job has already started asynchronously.
|
19
|
+
# # So you should check its progress.
|
20
|
+
# # if you want to wait for the job complete the task, try 'timeout' option.
|
21
|
+
# result = sf.data.upsert_resume job_id: jobinfo.id
|
22
|
+
#
|
23
|
+
# puts 'yey!' if result.job_info.completed? # the job has completed
|
24
|
+
#
|
25
|
+
# To know more about a job result, take a look at SfCli::Sf::Data module
|
26
|
+
#
|
27
|
+
# 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_data_commands_unified.htm#cli_reference_data_upsert_resume_unified]
|
28
|
+
#
|
29
|
+
def upsert_resume(job_id:, timeout: nil, target_org: nil)
|
30
|
+
flags = {
|
31
|
+
:"job-id" => job_id,
|
32
|
+
:"wait" => timeout,
|
33
|
+
:"target-org" => target_org,
|
34
|
+
}
|
35
|
+
action = __method__.to_s.tr('_', ' ')
|
36
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
37
|
+
|
38
|
+
job_info = ::SfCli::Sf::Data::JobInfo.new(**json['result']['jobInfo'])
|
39
|
+
return job_info unless json['result']['records']
|
40
|
+
|
41
|
+
::SfCli::Sf::Data::BulkResultV2.new(
|
42
|
+
job_info: job_info,
|
43
|
+
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
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
|