sf_cli 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +50 -0
- data/lib/sf_cli/sf/base.rb +34 -17
- data/lib/sf_cli/sf/data.rb +148 -38
- data/lib/sf_cli/sf/org.rb +49 -56
- data/lib/sf_cli/sf/project.rb +68 -74
- data/lib/sf_cli/sf/sobject.rb +41 -36
- data/lib/sf_cli/sf.rb +87 -33
- metadata +14 -12
- data/lib/sf_cli/helper_methods.rb +0 -26
- data/lib/sf_cli/sf/operations.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d070d17a818ef2dd2030a026e1e3b14a284eb1e4ce1bab9ed46c8f5811c2169
|
4
|
+
data.tar.gz: aa7aafc17f57d6d9df71e6969caad6c756965cfce76ca5583acd73799366b34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddfd91e3ddd1573938d9dbb9c27749eb8054475cee62d5565222f75ad2867fe1abf3dc3c5cc48a452a79991971532f89b233ddf1db491a83b9f28348fdd53eb0
|
7
|
+
data.tar.gz: 9df1154ec04b5acefddc469429163feed1ee432abd517048b0915d046c29d9d30a5e097153aa50a5774085720f91c68f86cda484ada9d667a6140cd15bcbe6bb
|
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Salesforce CLI library
|
2
|
+
https://badge.fury.io/rb/sf_cli.png
|
3
|
+
|
4
|
+
This is a class library for introducing {Salesforce CLI}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm] to Ruby scripting.<br>
|
5
|
+
It is designed to be similar usability to the command line interface.<br>
|
6
|
+
Currently only *sf* command is the target of development.
|
7
|
+
|
8
|
+
== prerequisite
|
9
|
+
Salesforce CLI must be installed.<br>
|
10
|
+
As of as of August in 2024, ver.2.54.6 is the development target.
|
11
|
+
|
12
|
+
== install
|
13
|
+
=== Rubygem
|
14
|
+
$ gem install sf_cli
|
15
|
+
|
16
|
+
=== Bundler
|
17
|
+
in Gemfile:
|
18
|
+
gem 'sf_cli'
|
19
|
+
|
20
|
+
then,
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
== Examples
|
24
|
+
require 'sf_cli/sf'
|
25
|
+
|
26
|
+
sf = SfCli::Sf.new
|
27
|
+
|
28
|
+
# login to org
|
29
|
+
sf.org.login_web
|
30
|
+
sf.org.login_web target_org: :dev # name an alias to the org, which you're going to log in, for later use. This is needed when you don't use the default org.
|
31
|
+
|
32
|
+
# get Account records
|
33
|
+
sf.data.query 'SELECT Id, Name FROM Account LIMIT 3' # => returns an array containing 3 records
|
34
|
+
|
35
|
+
Account = Struct.new(:Id, :Name)
|
36
|
+
sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
|
37
|
+
|
38
|
+
# generate a Salesforce DX project
|
39
|
+
sf.project.generate 'MyProject'
|
40
|
+
|
41
|
+
|
42
|
+
For more command details, see {Salesforce CLI Command Reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm]
|
43
|
+
|
44
|
+
== Documents
|
45
|
+
$ git clone https://github.com/tmkw/sf_cli.git
|
46
|
+
$ cd sf_cli
|
47
|
+
$ bundle install
|
48
|
+
$ bundle exec rake rdoc
|
49
|
+
|
50
|
+
This generates the documents in doc directory.
|
data/lib/sf_cli/sf/base.rb
CHANGED
@@ -1,17 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
module SfCli
|
2
|
+
class Sf
|
3
|
+
class Base
|
4
|
+
def initialize(_sf)
|
5
|
+
@sf = _sf
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def exec(action, flags: {}, switches: {}, redirection: nil)
|
11
|
+
sf.exec(category, action, flags: flags, switches: switches, redirection: redirection)
|
12
|
+
end
|
13
|
+
|
14
|
+
def category
|
15
|
+
self.class.name.split('::').last.downcase
|
16
|
+
end
|
17
|
+
|
18
|
+
def field_value_pairs(hash)
|
19
|
+
return nil if hash.nil?
|
20
|
+
return nil if hash.empty?
|
21
|
+
|
22
|
+
hash.each_with_object([]) do|(k,v), arr|
|
23
|
+
value = v.instance_of?(String) ? %|'#{v}'| : v
|
24
|
+
arr << %(#{k}=#{value})
|
25
|
+
end
|
26
|
+
.join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def sf
|
30
|
+
@sf
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/sf_cli/sf/data.rb
CHANGED
@@ -1,38 +1,148 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# *
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
json
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
class Sf
|
5
|
+
#
|
6
|
+
# ==== description
|
7
|
+
# The class representing *sf* *data*
|
8
|
+
#
|
9
|
+
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm
|
10
|
+
#
|
11
|
+
class Data < Base
|
12
|
+
|
13
|
+
# get object records using SQOL. (eqivalent to *sf* *data* *query*)
|
14
|
+
#
|
15
|
+
# *soql* --- SOQL<br>
|
16
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
17
|
+
# *model_class* --- the data model class representing the record object.<br>
|
18
|
+
#
|
19
|
+
# ==== examples
|
20
|
+
# sf.data.query('SELECT Id, Name From Account Limit 3') # returns an array of Hash object
|
21
|
+
#
|
22
|
+
# Account = Struct.new(:Id, :Name)
|
23
|
+
# sf.data.query('SELECT Id, Name From Account Limit 3', model_class: Account) # returns an array of Account struct object
|
24
|
+
#
|
25
|
+
def query(soql, target_org: nil, model_class: nil)
|
26
|
+
flags = {
|
27
|
+
:"query" => %("#{soql}"),
|
28
|
+
:"target-org" => target_org,
|
29
|
+
}
|
30
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
31
|
+
|
32
|
+
json['result']['records'].each_with_object([]) do |h, a|
|
33
|
+
h.delete "attributes"
|
34
|
+
a << (model_class ? model_class.new(**h) : h)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# get a object record. (eqivalent to *sf* *data* *get* *record*)
|
39
|
+
#
|
40
|
+
# *object_type* --- Object Type (ex. Account)<br>
|
41
|
+
# *record_id* --- id of the object<br>
|
42
|
+
# *where* --- hash object that is used to identify a record<br>
|
43
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
44
|
+
# *model_class* --- the data model class representing the record object.<br>
|
45
|
+
#
|
46
|
+
# ==== examples
|
47
|
+
# sf.data.get_record :Account, record_id: 'xxxxxxx'
|
48
|
+
# sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
49
|
+
#
|
50
|
+
# CustomObject = Struct.new(:Id, :Name)
|
51
|
+
# sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject struct object
|
52
|
+
#
|
53
|
+
def get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil)
|
54
|
+
where_conditions = field_value_pairs(where)
|
55
|
+
flags = {
|
56
|
+
:"sobject" => object_type,
|
57
|
+
:"record-id" => record_id,
|
58
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
59
|
+
:"target-org" => target_org,
|
60
|
+
}
|
61
|
+
action = __method__.to_s.tr('_', ' ')
|
62
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
63
|
+
|
64
|
+
result = json['result']
|
65
|
+
result.delete 'attributes'
|
66
|
+
|
67
|
+
model_class ? model_class.new(**result) : result
|
68
|
+
end
|
69
|
+
|
70
|
+
# update a object record. (eqivalent to *sf* *data* *update* *record*)
|
71
|
+
#
|
72
|
+
# *object_type* --- Object Type (ex. Account)<br>
|
73
|
+
# *record_id* --- id of the object<br>
|
74
|
+
# *where* --- field values that is used to identify a record<br>
|
75
|
+
# *values* --- field values for update<br>
|
76
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
77
|
+
#
|
78
|
+
# ==== examples
|
79
|
+
# sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
|
80
|
+
# sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
|
81
|
+
#
|
82
|
+
def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil)
|
83
|
+
where_conditions = field_value_pairs(where)
|
84
|
+
field_values = field_value_pairs(values)
|
85
|
+
flags = {
|
86
|
+
:"sobject" => object_type,
|
87
|
+
:"record-id" => record_id,
|
88
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
89
|
+
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
90
|
+
:"target-org" => target_org,
|
91
|
+
}
|
92
|
+
action = __method__.to_s.tr('_', ' ')
|
93
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
94
|
+
|
95
|
+
json['result']['id']
|
96
|
+
end
|
97
|
+
|
98
|
+
# create a object record. (eqivalent to *sf* *data* *create* *record*)
|
99
|
+
#
|
100
|
+
# *object_type* --- Object Type (ex. Account)<br>
|
101
|
+
# *values* --- field values to be assigned<br>
|
102
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
103
|
+
#
|
104
|
+
# ==== examples
|
105
|
+
#
|
106
|
+
# sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33} # creating a TheCustomObject record with name and age
|
107
|
+
#
|
108
|
+
def create_record(object_type, values: {}, target_org: nil)
|
109
|
+
field_values = field_value_pairs(values)
|
110
|
+
flags = {
|
111
|
+
:"sobject" => object_type,
|
112
|
+
:"values" => (field_values.nil? ? nil : %|"#{field_values}"|),
|
113
|
+
:"target-org" => target_org,
|
114
|
+
}
|
115
|
+
action = __method__.to_s.tr('_', ' ')
|
116
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
117
|
+
|
118
|
+
json['result']['id']
|
119
|
+
end
|
120
|
+
|
121
|
+
# delete a object record. (eqivalent to *sf* *data* *delete* *record*)
|
122
|
+
#
|
123
|
+
# *object_type* --- Object Type (ex. Account)<br>
|
124
|
+
# *record_id* --- id of the object<br>
|
125
|
+
# *where* --- hash object that is used to identify a record<br>
|
126
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
127
|
+
#
|
128
|
+
# ==== examples
|
129
|
+
# sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
|
130
|
+
# sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
131
|
+
#
|
132
|
+
#
|
133
|
+
def delete_record(object_type, record_id: nil, where: nil, target_org: nil)
|
134
|
+
where_conditions = field_value_pairs(where)
|
135
|
+
flags = {
|
136
|
+
:"sobject" => object_type,
|
137
|
+
:"record-id" => record_id,
|
138
|
+
:"where" => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
|
139
|
+
:"target-org" => target_org,
|
140
|
+
}
|
141
|
+
action = __method__.to_s.tr('_', ' ')
|
142
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
143
|
+
|
144
|
+
json['result']['id']
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/sf_cli/sf/org.rb
CHANGED
@@ -1,56 +1,49 @@
|
|
1
|
-
require_relative './base'
|
2
|
-
|
3
|
-
module SfCli
|
4
|
-
class Sf
|
5
|
-
#
|
6
|
-
# ==== description
|
7
|
-
# The class representing *sf* *org*.
|
8
|
-
#
|
9
|
-
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm
|
10
|
-
#
|
11
|
-
class Org < Base
|
12
|
-
ConnectionInfo = Struct.new(:access_token, :alias, :instance_url, :api_version, :status)
|
13
|
-
|
14
|
-
# login to the org by the browser.
|
15
|
-
#
|
16
|
-
# *
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
connection_info
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
class Sf
|
5
|
+
#
|
6
|
+
# ==== description
|
7
|
+
# The class representing *sf* *org*.
|
8
|
+
#
|
9
|
+
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm
|
10
|
+
#
|
11
|
+
class Org < Base
|
12
|
+
ConnectionInfo = Struct.new(:id, :access_token, :alias, :instance_url, :user_name, :api_version, :status)
|
13
|
+
|
14
|
+
# login to the org by the browser. (equivalent to *sf* *org* *login* *web*)
|
15
|
+
#
|
16
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
17
|
+
# *instance_url* --- custom login url.
|
18
|
+
#
|
19
|
+
def login_web(target_org: nil, instance_url: nil)
|
20
|
+
flags = {
|
21
|
+
:"alias" => target_org,
|
22
|
+
:"instance-url" => instance_url,
|
23
|
+
}
|
24
|
+
action = __method__.to_s.tr('_', ' ')
|
25
|
+
exec(action, flags: flags)
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# returns the org's connection information. (equivalent to *sf* *org* *display*)
|
30
|
+
#
|
31
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
32
|
+
#
|
33
|
+
def display(target_org: nil)
|
34
|
+
flags = {:"target-org" => target_org}
|
35
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
36
|
+
|
37
|
+
ConnectionInfo.new(
|
38
|
+
id: json['result']['id'],
|
39
|
+
access_token: json['result']['accessToken'],
|
40
|
+
alias: json['result']['alias'],
|
41
|
+
instance_url: json['result']['instanceUrl'],
|
42
|
+
user_name: json['result']['username'],
|
43
|
+
api_version: json['result']['apiVersion'],
|
44
|
+
status: json['result']['connectedStatus']
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/sf_cli/sf/project.rb
CHANGED
@@ -1,74 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
# generate a Salesforce project.
|
15
|
-
#
|
16
|
-
# *name* --- project name
|
17
|
-
#
|
18
|
-
# *
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
ensure
|
70
|
-
Dir.chdir base_dir
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
class Sf
|
5
|
+
# ==== description
|
6
|
+
# The class representing *sf* *project*
|
7
|
+
#
|
8
|
+
# command reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm
|
9
|
+
#
|
10
|
+
class Project < Base
|
11
|
+
GenerateResult = Struct.new(:output_dir, :files, :raw_output, :warnings)
|
12
|
+
|
13
|
+
#
|
14
|
+
# generate a Salesforce project. (equivalent to *sf* *project* *generate*)
|
15
|
+
#
|
16
|
+
# *name* --- project name<br>
|
17
|
+
# *template* --- project template name<br>
|
18
|
+
# *output_dir* --- output directory<br>
|
19
|
+
# *manifest* --- switch to create manifest file in the project directory (manifest/package.xml). default: false
|
20
|
+
#
|
21
|
+
def generate(name, manifest: false, template: nil, output_dir: nil)
|
22
|
+
flags = {
|
23
|
+
:name => name,
|
24
|
+
:template => template,
|
25
|
+
:"output-dir" => output_dir,
|
26
|
+
}
|
27
|
+
switches = {
|
28
|
+
manifest: manifest,
|
29
|
+
}
|
30
|
+
json = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr)
|
31
|
+
|
32
|
+
GenerateResult.new(
|
33
|
+
output_dir: json['result']['outputDir'],
|
34
|
+
files: json['result']['created'],
|
35
|
+
raw_output: json['result']['rawOutput'],
|
36
|
+
warnings: json['warnings']
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# generate the manifest file of a Salesforce project. (equivalent to *sf* *project* *generate* *manifest*)
|
41
|
+
#
|
42
|
+
# *metadata* --- an array that consists of metadata type like CustomObject, Layout and so on. (default: [])<br>
|
43
|
+
# *api_verson* --- api version (default: nil)<br>
|
44
|
+
# *output_dir* --- manifest's output directory in the project directory. You can use relative path from the project root (default: nil)<br>
|
45
|
+
# *from_org* --- username or alias of the org that contains the metadata components from which to build a manifest (default: nil)<br>
|
46
|
+
# *source_dir* --- paths to the local source files to include in the manifest (default: nil)
|
47
|
+
#
|
48
|
+
# ==== examples
|
49
|
+
# sf.project.generate_manifest metadata: %w[CustomObject Layout] # creates a package.xml, which is initialized with CustomObject and Layout
|
50
|
+
# sf.project.generate_manifest from_org: <org_name> # creates a package.xml, which is initialized with all metadata types in the org
|
51
|
+
#
|
52
|
+
def generate_manifest(name: nil, output_dir: nil, api_version: nil, metadata: [], from_org: nil, source_dir: nil)
|
53
|
+
flags = {
|
54
|
+
:name => name,
|
55
|
+
:"metadata" => (metadata.empty? ? nil : metadata.join(' ')),
|
56
|
+
:"from-org" => from_org,
|
57
|
+
:"source-dir" => source_dir,
|
58
|
+
:"output-dir" => output_dir,
|
59
|
+
:"api-version" => api_version,
|
60
|
+
}
|
61
|
+
action = __method__.to_s.tr('_', ' ')
|
62
|
+
json = exec(action, flags: flags, redirection: :null_stderr)
|
63
|
+
|
64
|
+
json['result']['path']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/sf_cli/sf/sobject.rb
CHANGED
@@ -1,36 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# *
|
16
|
-
#
|
17
|
-
def describe(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
class Sf
|
5
|
+
# ==== description
|
6
|
+
# The class representing *sf* *sobject*
|
7
|
+
#
|
8
|
+
# command reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_sobject_commands_unified.htm
|
9
|
+
#
|
10
|
+
class Sobject < Base
|
11
|
+
|
12
|
+
# returns a hash object containing the Salesforce object schema. (equivalent to *sf* *sobject* *describe*)
|
13
|
+
#
|
14
|
+
# *objectType* --- object type (ex: Account)<br>
|
15
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
16
|
+
#
|
17
|
+
def describe(object_type, target_org: nil)
|
18
|
+
flags = {
|
19
|
+
:"sobject" => object_type,
|
20
|
+
:"target-org" => target_org,
|
21
|
+
}
|
22
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
23
|
+
json['result']
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns a list of Salesforce object API name. (equivalent to *sf* *sobject* *list*)
|
27
|
+
#
|
28
|
+
# *object_type* --- all or custom<br>
|
29
|
+
# *target_org* --- an alias of paticular org, not default one<br>
|
30
|
+
#
|
31
|
+
def list(object_type, target_org: nil)
|
32
|
+
flags = {
|
33
|
+
:"sobject" => (object_type.to_sym == :custom ? :custom : :all),
|
34
|
+
:"target-org" => target_org,
|
35
|
+
}
|
36
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
37
|
+
json['result']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/sf_cli/sf.rb
CHANGED
@@ -1,33 +1,87 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module SfCli
|
4
|
-
# ==== description
|
5
|
-
# The main
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# sf
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module SfCli
|
4
|
+
# ==== description
|
5
|
+
# The main class of *sf* command.
|
6
|
+
#
|
7
|
+
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm
|
8
|
+
#
|
9
|
+
# ==== examples
|
10
|
+
# sf = SfCli::Sf.new # use default org
|
11
|
+
#
|
12
|
+
# # get the org connection infomation, as same as 'sf org display'
|
13
|
+
# sf.org.display
|
14
|
+
#
|
15
|
+
# # get Account records (equivalent to 'sf data query')
|
16
|
+
# sf.data.query 'SELECT Id, Name FROM Account LIMIT 3' # => returns an array containing 3 records
|
17
|
+
#
|
18
|
+
class Sf
|
19
|
+
OPERATION_CATEGORIES = %w[Org Sobject Data Project]
|
20
|
+
|
21
|
+
# load each operation class and define as a attribute
|
22
|
+
OPERATION_CATEGORIES.each do |category|
|
23
|
+
require_relative %(sf/#{category.downcase})
|
24
|
+
attr_reader category.downcase.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :varbose
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
OPERATION_CATEGORIES.each do |category|
|
31
|
+
instance_variable_set(:"@#{category.downcase}", Object.const_get(%|::SfCli::Sf::#{category}|).new(self))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def exec(category, action, flags: {}, switches: {}, redirection: nil)
|
36
|
+
cmd = %|sf #{category} #{action}#{as_flag_options(flags)}#{as_switch_options(switches)}#{redirect redirection}|
|
37
|
+
|
38
|
+
puts cmd if varbose
|
39
|
+
|
40
|
+
json = JSON.parse `#{cmd}`
|
41
|
+
|
42
|
+
puts json if varbose
|
43
|
+
|
44
|
+
raise StandardError.new(json['message']) if json['status'] != 0
|
45
|
+
|
46
|
+
json
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def as_flag_options(hash)
|
52
|
+
flag_options = hash.map{|k,v| flag k, v}.reject(&:nil?).join(' ')
|
53
|
+
flag_options = ' ' + flag_options unless flag_options.empty?
|
54
|
+
|
55
|
+
flag_options
|
56
|
+
end
|
57
|
+
|
58
|
+
def as_switch_options(hash)
|
59
|
+
' ' + {json: true}.merge(hash).each_with_object([]){|(k,v), arr| arr << %(--#{k}) if v}.join(' ')
|
60
|
+
end
|
61
|
+
|
62
|
+
def flag(name, arg)
|
63
|
+
arg ? %(--#{name} #{arg}) : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def os
|
67
|
+
@os ||= ENV['OS']
|
68
|
+
end
|
69
|
+
|
70
|
+
def redirect(option)
|
71
|
+
case option
|
72
|
+
when :null_stderr
|
73
|
+
null_stderr_redirection
|
74
|
+
else
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def null_stderr_redirection
|
79
|
+
@null_stderr_redirection ||=
|
80
|
+
if os.eql?('Windows_NT')
|
81
|
+
' 2>nul'
|
82
|
+
else
|
83
|
+
' 2> /dev/null'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takanobu Maekawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
command is
|
13
|
+
description: This is a class library for introducing Salesforce CLI.Currenty only
|
14
|
+
sf command is the target of development.
|
15
15
|
email:
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.rdoc
|
19
20
|
files:
|
21
|
+
- README.rdoc
|
20
22
|
- lib/sf_cli.rb
|
21
|
-
- lib/sf_cli/helper_methods.rb
|
22
23
|
- lib/sf_cli/sf.rb
|
23
24
|
- lib/sf_cli/sf/base.rb
|
24
25
|
- lib/sf_cli/sf/data.rb
|
25
|
-
- lib/sf_cli/sf/operations.rb
|
26
26
|
- lib/sf_cli/sf/org.rb
|
27
27
|
- lib/sf_cli/sf/project.rb
|
28
28
|
- lib/sf_cli/sf/sobject.rb
|
29
|
-
homepage:
|
29
|
+
homepage: https://github.com/tmkw/sf_cli
|
30
30
|
licenses:
|
31
31
|
- MIT
|
32
|
-
metadata:
|
32
|
+
metadata:
|
33
|
+
homepage_url: https://github.com/tmkw/sf_cli
|
33
34
|
post_install_message:
|
34
35
|
rdoc_options: []
|
35
36
|
require_paths:
|
@@ -38,15 +39,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
39
|
requirements:
|
39
40
|
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
42
|
+
version: 3.3.3
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
45
|
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
|
-
requirements:
|
48
|
+
requirements:
|
49
|
+
- 'Salesforce CLI ( >= 2.54.0): https://developer.salesforce.com/tools/salesforcecli'
|
48
50
|
rubygems_version: 3.5.11
|
49
51
|
signing_key:
|
50
52
|
specification_version: 4
|
51
|
-
summary: A
|
53
|
+
summary: A library for using Salesforce CLI in Ruby
|
52
54
|
test_files: []
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module SfCli
|
2
|
-
module HelperMethods
|
3
|
-
def os
|
4
|
-
@os ||= ENV['OS']
|
5
|
-
end
|
6
|
-
|
7
|
-
def null_stderr_redirection
|
8
|
-
@null_stderr_redirection ||=
|
9
|
-
if os.nil? || os.eql?('Windows_NT')
|
10
|
-
'2>nul'
|
11
|
-
else
|
12
|
-
'2> dev/null'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def flag(name, arg = nil, use_argument: true, long_flag: true)
|
17
|
-
flag_indicator = long_flag ? '--' : '-'
|
18
|
-
|
19
|
-
if use_argument
|
20
|
-
arg ? %(#{flag_indicator}#{name} #{arg}) : ''
|
21
|
-
else
|
22
|
-
%(#{flag_indicator}#{name})
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/sf_cli/sf/operations.rb
DELETED