sf_cli 0.0.7 → 0.0.9
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/{rdoc/README.rdoc → README.rdoc} +25 -39
- data/lib/sf_cli/console/commands.rb +52 -0
- data/lib/sf_cli/console.rb +5 -0
- data/lib/sf_cli/sf/apex/core.rb +5 -6
- data/lib/sf_cli/sf/apex/run.rb +32 -42
- data/lib/sf_cli/sf/core/base.rb +8 -0
- data/lib/sf_cli/sf/data/bulk_result_v2.rb +2 -3
- data/lib/sf_cli/sf/data/core.rb +5 -6
- data/lib/sf_cli/sf/data/create_record.rb +9 -9
- data/lib/sf_cli/sf/data/delete_bulk.rb +32 -16
- data/lib/sf_cli/sf/data/delete_record.rb +11 -10
- data/lib/sf_cli/sf/data/delete_resume.rb +14 -14
- data/lib/sf_cli/sf/data/get_record.rb +11 -13
- data/lib/sf_cli/sf/data/helper_methods.rb +1 -0
- data/lib/sf_cli/sf/data/query.rb +32 -35
- data/lib/sf_cli/sf/data/query_helper.rb +3 -0
- data/lib/sf_cli/sf/data/resume.rb +9 -7
- data/lib/sf_cli/sf/data/search.rb +12 -11
- data/lib/sf_cli/sf/data/update_record.rb +19 -20
- data/lib/sf_cli/sf/data/upsert_bulk.rb +33 -19
- data/lib/sf_cli/sf/data/upsert_resume.rb +12 -13
- data/lib/sf_cli/sf/main.rb +7 -3
- data/lib/sf_cli/sf/model/base_methods.rb +1 -0
- data/lib/sf_cli/sf/model/class_definition.rb +1 -0
- data/lib/sf_cli/sf/model/dml_methods.rb +1 -0
- data/lib/sf_cli/sf/model/generator.rb +2 -1
- data/lib/sf_cli/sf/model/query_condition.rb +1 -0
- data/lib/sf_cli/sf/model/query_methods.rb +6 -0
- data/lib/sf_cli/sf/model/sf_command_connection.rb +24 -5
- data/lib/sf_cli/sf/model.rb +6 -4
- data/lib/sf_cli/sf/org/core.rb +6 -6
- data/lib/sf_cli/sf/org/display.rb +10 -8
- data/lib/sf_cli/sf/org/list.rb +12 -13
- data/lib/sf_cli/sf/org/login.rb +22 -28
- data/lib/sf_cli/sf/project/core.rb +10 -72
- data/lib/sf_cli/sf/project/generate.rb +35 -0
- data/lib/sf_cli/sf/project/generate_manifest.rb +31 -0
- data/lib/sf_cli/sf/sobject/core.rb +10 -47
- data/lib/sf_cli/sf/sobject/describe.rb +31 -0
- data/lib/sf_cli/sf/sobject/list.rb +20 -0
- data/lib/sf_cli.rb +5 -12
- metadata +13 -12
- data/CHANGELOG.md +0 -57
- data/lib/sf_cli/sf/console.rb +0 -33
- data/rdoc/ObjectModel.rdoc +0 -83
data/lib/sf_cli/sf/data/query.rb
CHANGED
@@ -3,21 +3,18 @@ require_relative './query_helper'
|
|
3
3
|
|
4
4
|
module SfCli::Sf::Data
|
5
5
|
module Query
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# *timeout* --- max minutes to wait for the job complete in Bulk API mode<br>
|
19
|
-
#
|
20
|
-
# ======
|
6
|
+
# Get object records using SOQL.
|
7
|
+
# @param soql [String] SOQL
|
8
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
9
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
10
|
+
# @param model_class [Class] the object model class
|
11
|
+
# @param bulk [Boolean] use Bulk API
|
12
|
+
# @param wait [Integer] max minutes to wait for the job complete in Bulk API mode
|
13
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
14
|
+
#
|
15
|
+
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
16
|
+
#
|
17
|
+
# @example
|
21
18
|
# sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
|
22
19
|
#
|
23
20
|
# Account = Struct.new(:Id, :Name)
|
@@ -32,24 +29,23 @@ module SfCli::Sf::Data
|
|
32
29
|
# When using Bulk API, you get the records when the query job completes within time limit.
|
33
30
|
# The method returns a tapple(an array), which changes its contents according to the job result.
|
34
31
|
#
|
35
|
-
#
|
32
|
+
# @example
|
36
33
|
# 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,
|
38
|
-
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true,
|
34
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 5 # max wait 5 min to get result
|
35
|
+
# done, result = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 0 # returns immediately
|
39
36
|
#
|
40
37
|
# rows = result if done # if job is completed, the result is an array of record
|
41
38
|
# job_id = result unless done # if job hasn't completed or it has aborted, the result is the job ID
|
42
39
|
#
|
43
|
-
#
|
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.
|
40
|
+
# @see 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 command reference
|
46
41
|
#
|
47
|
-
def query(soql, target_org: nil, format: nil, bulk: false,
|
42
|
+
def query(soql, target_org: nil, format: nil, bulk: false, wait: nil, api_version: nil, model_class: nil)
|
48
43
|
flags = {
|
49
44
|
:"query" => %("#{soql}"),
|
50
45
|
:"target-org" => target_org,
|
51
46
|
:"result-format" => format,
|
52
|
-
:"wait" => (bulk ?
|
47
|
+
:"wait" => (bulk ? wait : nil),
|
48
|
+
:"api-version" => api_version,
|
53
49
|
}
|
54
50
|
switches = {
|
55
51
|
bulk: bulk,
|
@@ -62,19 +58,18 @@ module SfCli::Sf::Data
|
|
62
58
|
return_result(result, raw_output, bulk, model_class)
|
63
59
|
end
|
64
60
|
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
61
|
+
# Resume a bulk query job, which you previously started, and get records
|
62
|
+
# @param job_id [String] job ID you want to resume
|
63
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
64
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available
|
65
|
+
# @param model_class [Class] the object model class
|
66
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
68
67
|
#
|
69
|
-
#
|
68
|
+
# @return [Array,[String,Array]] records or a tuple containing a flag and records
|
70
69
|
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# *model_class* --- the object model class<br>
|
74
|
-
#
|
75
|
-
# ======
|
70
|
+
# @example
|
76
71
|
# # start a query job
|
77
|
-
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true,
|
72
|
+
# result1 = sf.data.query 'SELECT Id, Name FROM Account', bulk: true, wait: 0 # returns immediately
|
78
73
|
#
|
79
74
|
# result1 # => [false, "<job id>"]
|
80
75
|
#
|
@@ -86,12 +81,14 @@ module SfCli::Sf::Data
|
|
86
81
|
#
|
87
82
|
# result2 # => if done is true, this is an array of record. Otherwise it should be the Job ID.
|
88
83
|
#
|
89
|
-
#
|
90
|
-
|
84
|
+
# @see 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 command reference
|
85
|
+
#
|
86
|
+
def query_resume(job_id:, target_org: nil, format: nil, api_version: nil, model_class: nil)
|
91
87
|
flags = {
|
92
88
|
:"bulk-query-id" => job_id,
|
93
89
|
:"target-org" => target_org,
|
94
90
|
:"result-format" => format,
|
91
|
+
:"api-version" => api_version,
|
95
92
|
}
|
96
93
|
raw_output = format ? true : false
|
97
94
|
format = format || :json
|
@@ -2,6 +2,7 @@ require_relative './helper_methods'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module Query
|
5
|
+
# @private
|
5
6
|
class RegularResultAdjuster # :nodoc: all
|
6
7
|
include ::SfCli::Sf::Data::HelperMethods
|
7
8
|
|
@@ -20,6 +21,7 @@ module SfCli::Sf::Data
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
# @private
|
23
25
|
class BulkResultAdjuster # :nodoc: all
|
24
26
|
include ::SfCli::Sf::Data::HelperMethods
|
25
27
|
|
@@ -42,6 +44,7 @@ module SfCli::Sf::Data
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
47
|
+
# @private
|
45
48
|
class RawOutputResultAdjuster # :nodoc: all
|
46
49
|
attr_reader :result
|
47
50
|
|
@@ -49,12 +49,13 @@ module SfCli::Sf::Data
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# View the status of a bulk job.
|
52
|
+
# @param job_id [String] job ID you want to resume
|
53
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
54
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
52
55
|
#
|
53
|
-
#
|
56
|
+
# @return [JobInfo] job information
|
54
57
|
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# ======
|
58
|
+
# @example
|
58
59
|
# # start a delete job
|
59
60
|
# jobinfo = sf.data.delete_bulk sobject: :TestCustomObject__c, file: 'delete.csv' # this returns immediately
|
60
61
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -69,14 +70,15 @@ module SfCli::Sf::Data
|
|
69
70
|
# - in_progress?
|
70
71
|
# - completed?
|
71
72
|
#
|
72
|
-
# To know job status more, take a look at {
|
73
|
+
# To know job status more, take a look at {https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/bulk_api_2_job_states.htm the bulk API developer guide}
|
73
74
|
#
|
74
|
-
#
|
75
|
+
# @see 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 command reference
|
75
76
|
#
|
76
|
-
def resume(job_id:, target_org: nil)
|
77
|
+
def resume(job_id:, target_org: nil, api_version: nil)
|
77
78
|
flags = {
|
78
79
|
:"job-id" => job_id,
|
79
80
|
:"target-org" => target_org,
|
81
|
+
:"api-version" => api_version,
|
80
82
|
}
|
81
83
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
82
84
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module Search
|
3
|
-
#
|
3
|
+
# Search objects using SOSL.
|
4
|
+
# @param sosl [String] SOSL
|
5
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
6
|
+
# @param format [Symbol,String] get the command's raw output. human, csv, json can be available.
|
7
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
4
8
|
#
|
5
|
-
#
|
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):
|
9
|
+
# @return [Hash] the search result
|
10
|
+
# @note if you choose csv as format, csv files are downloaded in current directory
|
13
11
|
#
|
12
|
+
# @example
|
13
|
+
# (in irb):
|
14
14
|
# > sf.data.search "FIND {TIM OR YOUNG OR OIL} IN Name Fields"
|
15
15
|
# =>
|
16
16
|
# {"Lead"=>["00Q5j00000WgEuDEAV"],
|
@@ -24,13 +24,14 @@ module SfCli::Sf::Data
|
|
24
24
|
# "0065j00001XHJLJAA5"],
|
25
25
|
# "User"=>["0055j00000CcL2bAAF", "0055j00000CcL1YAAV"]}
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# @see 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 command reference
|
28
28
|
#
|
29
|
-
def search(sosl, target_org: nil, format: nil)
|
29
|
+
def search(sosl, target_org: nil, format: nil, api_version: nil)
|
30
30
|
flags = {
|
31
31
|
:"query" => %|"#{sosl}"|,
|
32
32
|
:"target-org" => target_org,
|
33
33
|
:"result-format" => format,
|
34
|
+
:"api-version" => api_version,
|
34
35
|
}
|
35
36
|
raw_output = format ? true : false
|
36
37
|
format = format&.to_sym || :json
|
@@ -1,33 +1,32 @@
|
|
1
1
|
module SfCli::Sf::Data
|
2
2
|
module UpdateRecord
|
3
3
|
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# ==== examples
|
4
|
+
# Update a object record.
|
5
|
+
# @param object_type [Symbol,String] object type(ex. Account)
|
6
|
+
# @param record_id [String] ID of the object
|
7
|
+
# @param where [Hash] field values to identify a record
|
8
|
+
# @param values [Hash] field values for update
|
9
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
10
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
11
|
+
#
|
12
|
+
# @return [String] ID of the record updated
|
13
|
+
#
|
14
|
+
# @example
|
17
15
|
# sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
|
18
16
|
# sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
|
19
17
|
#
|
20
|
-
#
|
18
|
+
# @see 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 command reference
|
21
19
|
#
|
22
|
-
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
|
20
|
+
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil, api_version: nil)
|
23
21
|
where_conditions = field_value_pairs(where)
|
24
22
|
field_values = field_value_pairs(values)
|
25
23
|
flags = {
|
26
|
-
:"sobject"
|
27
|
-
:"record-id"
|
28
|
-
:"where"
|
29
|
-
:"values"
|
30
|
-
:"target-org"
|
24
|
+
:"sobject" => object_type,
|
25
|
+
:"record-id" => record_id,
|
26
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
27
|
+
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
28
|
+
:"target-org" => target_org,
|
29
|
+
:"api-version" => api_version,
|
31
30
|
}
|
32
31
|
action = __method__.to_s.tr('_', ' ')
|
33
32
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -2,19 +2,19 @@ require_relative './bulk_result_v2'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module UpsertBulk
|
5
|
-
#
|
5
|
+
# Update records using Bulk API 2.0
|
6
|
+
# @param file [String,#read]
|
7
|
+
# (1)path of a CSV file, which is written record IDs to delete.
|
8
|
+
# (2) IO-like object, which has #read method
|
9
|
+
# @param sobject [Symbol,String] object type(ex. Account)
|
10
|
+
# @param external_id [String] name of the external ID field.Otherwise it must be Id
|
11
|
+
# @param wait [Integer] max minutes to wait for the job complete the task
|
12
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
13
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
6
14
|
#
|
7
|
-
#
|
15
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
8
16
|
#
|
9
|
-
#
|
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
|
-
# ======
|
17
|
+
# @example
|
18
18
|
# # start a upsert job
|
19
19
|
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv' # this returns immediately
|
20
20
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
@@ -23,17 +23,29 @@ module SfCli::Sf::Data
|
|
23
23
|
# sf.data.upsert_resume job_id: jobinfo.id
|
24
24
|
#
|
25
25
|
# # Or, you can wait for the job completion with one try.
|
26
|
-
# result = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv',
|
26
|
+
# result = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', wait: 5 # wait within 5 minutes
|
27
|
+
#
|
28
|
+
# # you can use IO-like object, which has #read, to `file` keyword:
|
29
|
+
# require 'stringio'
|
30
|
+
# csv = StringIO.new <<CSV
|
31
|
+
# Id,Name
|
32
|
+
# 001J400000Ki61uIAB,John Smith
|
33
|
+
# 001J400000Ki3WRIAZ,Foo Baz Bar
|
34
|
+
# CSV
|
35
|
+
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: csv
|
27
36
|
#
|
28
|
-
#
|
37
|
+
# @see 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 command reference
|
29
38
|
#
|
30
|
-
def upsert_bulk(file:, sobject:, external_id:,
|
39
|
+
def upsert_bulk(file:, sobject:, external_id:, wait: nil, target_org: nil, api_version: nil)
|
40
|
+
_file = create_tmpfile_by_io(file)
|
41
|
+
path = _file&.path || file
|
31
42
|
flags = {
|
32
|
-
:"file"
|
33
|
-
:"sobject"
|
34
|
-
:"external-id"
|
35
|
-
:"wait"
|
36
|
-
:"target-org"
|
43
|
+
:"file" => path,
|
44
|
+
:"sobject" => sobject,
|
45
|
+
:"external-id" => external_id,
|
46
|
+
:"wait" => wait,
|
47
|
+
:"target-org" => target_org,
|
48
|
+
:"api-version" => api_version,
|
37
49
|
}
|
38
50
|
action = __method__.to_s.tr('_', ' ')
|
39
51
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
@@ -45,6 +57,8 @@ module SfCli::Sf::Data
|
|
45
57
|
job_info: job_info,
|
46
58
|
records: ::SfCli::Sf::Data::BulkRecordsV2.new(**json['result']['records'])
|
47
59
|
)
|
60
|
+
ensure
|
61
|
+
_file&.close!
|
48
62
|
end
|
49
63
|
end
|
50
64
|
end
|
@@ -2,35 +2,34 @@ require_relative './bulk_result_v2'
|
|
2
2
|
|
3
3
|
module SfCli::Sf::Data
|
4
4
|
module UpsertResume
|
5
|
-
#
|
5
|
+
# Resume a bulk upsert job you previously started with Bulk API 2.0 and return a bulk result object.
|
6
|
+
# @param job_id [String] job ID you want to resume
|
7
|
+
# @param wait [Integer] max minutes to wait for the job complete the task
|
8
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
9
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
6
10
|
#
|
7
|
-
#
|
11
|
+
# @return [JobInfo, BulkResultV2] the job result, whose type is changed by situation
|
8
12
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# *target_org* --- an alias of paticular org, or username can be used<br>
|
12
|
-
#
|
13
|
-
# ======
|
13
|
+
# @example
|
14
14
|
# # start a upsert job
|
15
15
|
# jobinfo = sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv' # this returns immediately
|
16
16
|
# jobinfo.id # => "750J4000003g1OaIAI" it's job ID
|
17
17
|
#
|
18
18
|
# # the job has already started asynchronously.
|
19
19
|
# # So you should check its progress.
|
20
|
-
# # if you want to wait for the job complete the task, try '
|
20
|
+
# # if you want to wait for the job complete the task, try 'wait' option.
|
21
21
|
# result = sf.data.upsert_resume job_id: jobinfo.id
|
22
22
|
#
|
23
23
|
# puts 'yey!' if result.job_info.completed? # the job has completed
|
24
24
|
#
|
25
|
-
#
|
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]
|
25
|
+
# @see 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 command reference
|
28
26
|
#
|
29
|
-
def upsert_resume(job_id:,
|
27
|
+
def upsert_resume(job_id:, wait: nil, target_org: nil, api_version: nil)
|
30
28
|
flags = {
|
31
29
|
:"job-id" => job_id,
|
32
|
-
:"wait" =>
|
30
|
+
:"wait" => wait,
|
33
31
|
:"target-org" => target_org,
|
32
|
+
:"api-version" => api_version,
|
34
33
|
}
|
35
34
|
action = __method__.to_s.tr('_', ' ')
|
36
35
|
json = exec(action, flags: flags, redirection: :null_stderr)
|
data/lib/sf_cli/sf/main.rb
CHANGED
@@ -3,14 +3,15 @@ require 'json'
|
|
3
3
|
|
4
4
|
module SfCli
|
5
5
|
module Sf
|
6
|
-
|
7
|
-
# The entry class of sf command. It is returned by sf method.
|
6
|
+
|
7
|
+
# The entry class of sf command. It is returned by the sf method.
|
8
8
|
# With including Singleton module, the instance of this class is guaranteed as singleton.
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# @example
|
11
11
|
# sf # returns a instance of SfCli::Sf
|
12
12
|
# sf.org.display # you can follow the similar syntax to the original command by using method chain.
|
13
13
|
#
|
14
|
+
# @private :nodoc: just for developers
|
14
15
|
class Main
|
15
16
|
include Singleton
|
16
17
|
|
@@ -21,6 +22,9 @@ module SfCli
|
|
21
22
|
attr_reader category.downcase.to_sym
|
22
23
|
end
|
23
24
|
|
25
|
+
# Generate each sub command object such as org, data and sobject
|
26
|
+
# so that it can chain like `sf.org.display`.
|
27
|
+
#
|
24
28
|
def initialize
|
25
29
|
OPERATION_CATEGORIES.each do |category|
|
26
30
|
instance_variable_set(:"@#{category.downcase}", Object.const_get(%|::SfCli::Sf::#{category}::Core|).new)
|
@@ -3,8 +3,9 @@ require_relative './class_definition'
|
|
3
3
|
module SfCli
|
4
4
|
module Sf
|
5
5
|
module Model
|
6
|
+
# @private :nodoc: just for developers
|
6
7
|
class Generator
|
7
|
-
attr_reader :
|
8
|
+
attr_reader :connection
|
8
9
|
|
9
10
|
def initialize(connection)
|
10
11
|
@connection = connection
|
@@ -3,6 +3,7 @@ require_relative './query_condition'
|
|
3
3
|
module SfCli
|
4
4
|
module Sf
|
5
5
|
module Model
|
6
|
+
# @private :nodoc: just for developers
|
6
7
|
module QueryMethods
|
7
8
|
def self.included(c)
|
8
9
|
c.extend ClassMethods
|
@@ -25,6 +26,11 @@ module SfCli
|
|
25
26
|
connection.find(name.to_sym, id, Object.const_get(name.to_sym))
|
26
27
|
end
|
27
28
|
|
29
|
+
def find_by(*find_condition)
|
30
|
+
qc = QueryCondition.new(connection, self.name, self.field_names)
|
31
|
+
qc.where(*find_condition).take
|
32
|
+
end
|
33
|
+
|
28
34
|
def limit(num)
|
29
35
|
qc = QueryCondition.new(connection, self.name, self.field_names)
|
30
36
|
qc.limit(num)
|
@@ -5,9 +5,18 @@ require_relative '../org/core'
|
|
5
5
|
module SfCli
|
6
6
|
module Sf
|
7
7
|
module Model
|
8
|
+
#
|
9
|
+
# Connection object to access Salesforce based on Sf command
|
10
|
+
#
|
8
11
|
class SfCommandConnection
|
9
|
-
attr_reader :
|
12
|
+
attr_reader :target_org, :instance_url
|
10
13
|
|
14
|
+
# @private :nodoc: just for developers
|
15
|
+
attr_reader :sf_data, :sf_org, :sf_sobject
|
16
|
+
|
17
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
18
|
+
# @param instance_url [String] URL of the instance that the org lives on.
|
19
|
+
#
|
11
20
|
def initialize(target_org: nil, instance_url: nil)
|
12
21
|
@sf_org = ::SfCli::Sf::Org::Core.new
|
13
22
|
@sf_data = ::SfCli::Sf::Data::Core.new
|
@@ -24,10 +33,20 @@ module SfCli
|
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
36
|
+
# Sf command style query interface for Model module
|
37
|
+
#
|
38
|
+
# For query details, see {SfCli::Sf::Data::Query sf data query}
|
39
|
+
#
|
40
|
+
def exec_query(soql, format: nil, bulk: false, wait: nil, model_class: nil)
|
41
|
+
sf_data.query(soql, target_org: target_org, format: format, bulk: bulk, wait: wait, model_class: model_class)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @private :nodoc: just for developers
|
27
45
|
def find(object_type, id, klass)
|
28
46
|
sf_data.get_record object_type, record_id: id, target_org: target_org, model_class: klass
|
29
47
|
end
|
30
48
|
|
49
|
+
# @private :nodoc: just for developers
|
31
50
|
def create(object_type, values, klass = nil)
|
32
51
|
id = sf_data.create_record object_type, values: values, target_org: target_org
|
33
52
|
return id if klass.nil?
|
@@ -35,22 +54,22 @@ module SfCli
|
|
35
54
|
find(object_type, id, klass)
|
36
55
|
end
|
37
56
|
|
57
|
+
# @private :nodoc: just for developers
|
38
58
|
def update(object_type, id, values)
|
39
59
|
sf_data.update_record object_type, record_id: id, where: nil, values: values, target_org: target_org
|
40
60
|
end
|
41
61
|
|
62
|
+
# @private :nodoc: just for developers
|
42
63
|
def delete(object_type, id)
|
43
64
|
sf_data.delete_record object_type, record_id: id, where: nil, target_org: target_org
|
44
65
|
end
|
45
66
|
|
67
|
+
# @private :nodoc: just for developers
|
46
68
|
def query(soql, klass)
|
47
69
|
sf_data.query soql, target_org: target_org, model_class: klass
|
48
70
|
end
|
49
71
|
|
50
|
-
|
51
|
-
sf_data.query(soql, target_org: target_org, format: format, bulk: bulk, timeout: timeout, model_class: model_class)
|
52
|
-
end
|
53
|
-
|
72
|
+
# @private :nodoc: just for developers
|
54
73
|
def describe(object_type)
|
55
74
|
sf_sobject.describe(object_type, target_org: target_org)
|
56
75
|
end
|
data/lib/sf_cli/sf/model.rb
CHANGED
@@ -3,20 +3,22 @@ require_relative 'model/generator'
|
|
3
3
|
module SfCli
|
4
4
|
module Sf
|
5
5
|
#
|
6
|
-
#
|
7
|
-
# The module for \Object \Model definition and generation
|
8
|
-
#
|
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.
|
6
|
+
# The module for object model definition and generation
|
10
7
|
#
|
11
8
|
module Model
|
9
|
+
# The connection object to access Salesforce
|
12
10
|
def self.connection
|
13
11
|
@@connection
|
14
12
|
end
|
15
13
|
|
14
|
+
# set the connection
|
16
15
|
def self.set_connection(conn)
|
17
16
|
@@connection = conn
|
18
17
|
end
|
19
18
|
|
19
|
+
# generate object models
|
20
|
+
# @param object_names [Array] a list of object name
|
21
|
+
#
|
20
22
|
def self.generate(object_names)
|
21
23
|
generator = Generator.new(connection)
|
22
24
|
|
data/lib/sf_cli/sf/org/core.rb
CHANGED
@@ -5,13 +5,13 @@ require_relative './list'
|
|
5
5
|
|
6
6
|
module SfCli
|
7
7
|
module Sf
|
8
|
+
#
|
9
|
+
# Org Commands
|
10
|
+
#
|
11
|
+
# @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm command reference
|
12
|
+
#
|
8
13
|
module Org
|
9
|
-
#
|
10
|
-
# ==== description
|
11
|
-
# The class representing *sf* *org*.
|
12
|
-
#
|
13
|
-
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm
|
14
|
-
#
|
14
|
+
# @private :nodoc: just for developers
|
15
15
|
class Core
|
16
16
|
include ::SfCli::Sf::Core::Base
|
17
17
|
include Login
|
@@ -3,13 +3,15 @@ module SfCli::Sf::Org
|
|
3
3
|
ConnectionInfo = Struct.new(:id, :access_token, :alias, :instance_url, :user_name, :api_version, :status)
|
4
4
|
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# Returns the org's connection information
|
7
|
+
# @param target_org [Symbol,String] an alias of paticular org, or username can be used
|
8
|
+
# @param api_version [Numeric] override the api version used for api requests made by this command
|
7
9
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# ======
|
11
|
-
# # example (in irb):
|
10
|
+
# @note this function returns the org information including security sensitive things such as access token, username and so on.
|
11
|
+
# @return [ConnectionInfo] the org's connection information
|
12
12
|
#
|
13
|
+
# @example
|
14
|
+
# (in irb):
|
13
15
|
# > sf.org.display
|
14
16
|
# =>
|
15
17
|
# #<struct SfCli::Sf::Org::Display::ConnectionInfo
|
@@ -21,10 +23,10 @@ module SfCli::Sf::Org
|
|
21
23
|
# api_version="61.0",
|
22
24
|
# status="Connected">
|
23
25
|
#
|
24
|
-
#
|
26
|
+
# @see 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 command reference
|
25
27
|
#
|
26
|
-
def display(target_org: nil)
|
27
|
-
flags = {:"target-org" => target_org}
|
28
|
+
def display(target_org: nil, api_version: nil)
|
29
|
+
flags = {:"target-org" => target_org, :"api-version" => api_version}
|
28
30
|
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
29
31
|
|
30
32
|
ConnectionInfo.new(
|