sf_cli 0.0.7.beta → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/sf_cli/sf/apex/core.rb +19 -0
- data/lib/sf_cli/sf/apex/run.rb +110 -0
- data/lib/sf_cli/sf/console.rb +7 -0
- data/lib/sf_cli/sf/main.rb +1 -1
- data/lib/sf_cli/sf/model/query_condition.rb +1 -1
- data/{README.rdoc → rdoc/ObjectModel.rdoc} +1 -59
- data/rdoc/README.rdoc +79 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98f07645a79ccfa6a8f8bbac048a4da5aae6f21bf294445a0888f861d91b8f27
|
4
|
+
data.tar.gz: a608a4eeb21ff2fd065cac874d6834e1a6c8aec83f9a40ada0f73917e4029ffb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f5949bdba034feb1a7265a79fa9cd41c9e6f9d1402e4cf173fc585b0ab44d904570591382066633f5258f55503f0503410d648fb3700856029471678090efed
|
7
|
+
data.tar.gz: 32a39625a575b1f9e465d9090c1e63a0ec8ee8ed605c4f5c3104b3866121a931780cf7c2f82200ab84ca5924ff798790cf116cf9580280ab1e1e6a26458d1ef4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
## 0.0.7 - 2024-09-19
|
2
|
+
- NEW: add `sf.apex.run`
|
1
3
|
## 0.0.6 - 2024-09-16
|
2
4
|
- NEW: Object Model Support renewal;
|
3
5
|
- `SfCli::Sf::Model.connection` represents the connection to Salesforce. It can be set by `set_connection` class method in the module. As of now there is only `SfCommandConnection`, which is based on sf command, as connection adapter. After the connection is set by `set_connection`, it is also automatically set to classes when `SfCli::Sf::Model.generate` method is called.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../core/base'
|
2
|
+
require_relative './run'
|
3
|
+
|
4
|
+
module SfCli
|
5
|
+
module Sf
|
6
|
+
module Apex
|
7
|
+
#
|
8
|
+
# ==== description
|
9
|
+
# The class representing *sf* *apex*.
|
10
|
+
#
|
11
|
+
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm
|
12
|
+
#
|
13
|
+
class Core
|
14
|
+
include ::SfCli::Sf::Core::Base
|
15
|
+
include Run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module SfCli::Sf::Apex
|
5
|
+
module Run
|
6
|
+
#
|
7
|
+
# run apex code and returns its result
|
8
|
+
#
|
9
|
+
# *target_org* --- an alias of paticular org, or username can be used<br>
|
10
|
+
#
|
11
|
+
# *file* --- (1) path to a local file that contains \Apex code. (2) StringIO object
|
12
|
+
#
|
13
|
+
# == Examples
|
14
|
+
# Execute apex code in a file
|
15
|
+
# result = sf.apex.run file: "path/to/apex"
|
16
|
+
# result.success # true if the execution succeeds
|
17
|
+
# result.logs # execution log
|
18
|
+
#
|
19
|
+
# StringIO is usable instead of file path
|
20
|
+
# require 'stringio'
|
21
|
+
#
|
22
|
+
# pseudo_file = StringIO.new <<~EOS
|
23
|
+
# Account acc = [SELECT Id, Name FROM Account Limit 1];
|
24
|
+
# System.debug(acc.Name);
|
25
|
+
# EOS
|
26
|
+
#
|
27
|
+
# sf.apex.run target_org: :dev, file: pseudo_file
|
28
|
+
#
|
29
|
+
# == Interactive Mode
|
30
|
+
#
|
31
|
+
# If you don't specify *file* argument, it starts interactive mode that may be helpful in IRB environment.
|
32
|
+
# irb(main:) > sf.apex.run target_org: :dev
|
33
|
+
#
|
34
|
+
# Account acc = [SELECT Id, Name FROM Account LIMIT 1];
|
35
|
+
# System.debug(acc.Name);
|
36
|
+
# <press Ctrl-D>
|
37
|
+
#
|
38
|
+
# =>
|
39
|
+
# #<SfCli::Sf::Apex::Run::ApexResult:0x00007437b4e13218
|
40
|
+
# @column=-1,
|
41
|
+
# @compile_problem="",
|
42
|
+
# @compiled=true,
|
43
|
+
# @exception_message="",
|
44
|
+
# @exception_stack_trace="",
|
45
|
+
# @line=-1,
|
46
|
+
# @logs=
|
47
|
+
# ["61.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO",
|
48
|
+
# "Execute Anonymous: Account acc = [SELECT Id, Name FROM Account LIMIT 1];",
|
49
|
+
# "Execute Anonymous: System.debug(acc.Name);",
|
50
|
+
# ....]
|
51
|
+
# 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_apex_commands_unified.htm#cli_reference_apex_run_unified]
|
52
|
+
#
|
53
|
+
def run(target_org: nil, file: nil)
|
54
|
+
return run_interactive(target_org) if file.nil?
|
55
|
+
return run_by_io(target_org, file) if file.is_a? StringIO
|
56
|
+
|
57
|
+
return unless file.is_a? String
|
58
|
+
|
59
|
+
flags = {:"target-org" => target_org, :"file" => file}
|
60
|
+
|
61
|
+
json = exec(__method__, flags: flags, redirection: :null_stderr)
|
62
|
+
ApexResult.new(json['result'])
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def run_by_io(target_org, io)
|
68
|
+
file = Tempfile.open(%w[sf apex]){|f| f.write(io.read); f}
|
69
|
+
|
70
|
+
flags = {:"target-org" => target_org, :"file" => file.path}
|
71
|
+
json = exec(:run, flags: flags, redirection: :null_stderr)
|
72
|
+
ApexResult.new(json['result'])
|
73
|
+
ensure
|
74
|
+
file&.close!
|
75
|
+
end
|
76
|
+
|
77
|
+
def run_interactive(target_org)
|
78
|
+
file = Tempfile.open(%w[sf apex]) do |f|
|
79
|
+
s = $stdin.gets
|
80
|
+
while s
|
81
|
+
f.puts(s)
|
82
|
+
s = $stdin.gets
|
83
|
+
end
|
84
|
+
f
|
85
|
+
end
|
86
|
+
|
87
|
+
flags = {:"target-org" => target_org, :"file" => file.path}
|
88
|
+
|
89
|
+
json = exec(:run, flags: flags, redirection: :null_stderr)
|
90
|
+
ApexResult.new(json['result'])
|
91
|
+
ensure
|
92
|
+
file&.close!
|
93
|
+
end
|
94
|
+
|
95
|
+
class ApexResult
|
96
|
+
attr_reader :success, :compiled, :compile_problem, :exception_message, :exception_stack_trace, :line, :column, :logs
|
97
|
+
|
98
|
+
def initialize(attributes)
|
99
|
+
@success = attributes['success']
|
100
|
+
@compiled = attributes['compiled']
|
101
|
+
@compile_problem = attributes['compileProblem']
|
102
|
+
@exception_message = attributes['exceptionMessage']
|
103
|
+
@exception_stack_trace = attributes['exceptionStackTrace']
|
104
|
+
@line = attributes['line']
|
105
|
+
@column = attributes['column']
|
106
|
+
@logs = attributes['logs'].chomp.split("\n")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/sf_cli/sf/console.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'sf_cli'
|
2
2
|
require 'sf_cli/sf/model'
|
3
3
|
require 'sf_cli/sf/model/sf_command_connection'
|
4
|
+
require 'stringio'
|
4
5
|
|
5
6
|
def sf_init(org_alias)
|
6
7
|
org_info = sf.org.display target_org: org_alias
|
@@ -20,7 +21,13 @@ def target_org
|
|
20
21
|
connection.target_org
|
21
22
|
end
|
22
23
|
|
24
|
+
def apex(apex_code)
|
25
|
+
sf.apex.run target_org: target_org, file: StringIO.new(apex_code)
|
26
|
+
end
|
27
|
+
|
23
28
|
alias :sfinit :sf_init
|
24
29
|
alias :gen :generate
|
25
30
|
alias :conn :connection
|
26
31
|
alias :org :target_org
|
32
|
+
|
33
|
+
sfinit ARGV[0]
|
data/lib/sf_cli/sf/main.rb
CHANGED
@@ -14,7 +14,7 @@ module SfCli
|
|
14
14
|
class Main
|
15
15
|
include Singleton
|
16
16
|
|
17
|
-
OPERATION_CATEGORIES = %w[Org Sobject Data Project]
|
17
|
+
OPERATION_CATEGORIES = %w[Org Sobject Data Project Apex]
|
18
18
|
|
19
19
|
OPERATION_CATEGORIES.each do |category|
|
20
20
|
require_relative %(#{category.downcase}/core)
|
@@ -1,53 +1,4 @@
|
|
1
|
-
|
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 original command.<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 September in 2024, ver.2.56.7 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
|
-
=== Since 0.0.4
|
25
|
-
require 'sf_cli'
|
26
|
-
|
27
|
-
# login to org
|
28
|
-
sf.org.login_web
|
29
|
-
|
30
|
-
# get records
|
31
|
-
sf.data.query 'SELECT Id, Name FROM Account LIMIT 1' # => [{Id: "abc", Name: "account name"}]
|
32
|
-
|
33
|
-
# generate a Salesforce DX project
|
34
|
-
sf.project.generate 'MyProject'
|
35
|
-
|
36
|
-
=== Before 0.0.3
|
37
|
-
require 'sf_cli/sf'
|
38
|
-
|
39
|
-
sf = SfCli::Sf.new
|
40
|
-
|
41
|
-
# login to org
|
42
|
-
sf.org.login_web
|
43
|
-
|
44
|
-
# get Account records
|
45
|
-
sf.data.query 'SELECT Id, Name FROM Account LIMIT 3' # => returns an array containing 3 records
|
46
|
-
|
47
|
-
# generate a Salesforce DX project
|
48
|
-
sf.project.generate 'MyProject'
|
49
|
-
|
50
|
-
== \Object Model support (experimental, since 0.0.4)
|
1
|
+
== \Object Model support
|
51
2
|
=== generate Models
|
52
3
|
require 'sf_cli/sf/model'
|
53
4
|
require 'sf_cli/sf/model/sf_command_connection'
|
@@ -130,12 +81,3 @@ then,
|
|
130
81
|
schema = Account.describe
|
131
82
|
schema.name # Account
|
132
83
|
schema.field_names # [Id, Name, ....]
|
133
|
-
|
134
|
-
== Documents
|
135
|
-
The following steps generate *doc* directory, which all documents are generated in.
|
136
|
-
$ git clone https://github.com/tmkw/sf_cli.git
|
137
|
-
$ cd sf_cli
|
138
|
-
$ bundle install
|
139
|
-
$ bundle exec rake rdoc
|
140
|
-
|
141
|
-
*Or*, you can read the same documents online at {rubygems.org}[https://rubygems.org/gems/sf_cli]
|
data/rdoc/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= Salesforce CLI library for Ruby
|
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 original command.<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 September in 2024, ver.2.56.7 is the development target.
|
11
|
+
|
12
|
+
== install
|
13
|
+
Rubygem::
|
14
|
+
the simplest way:
|
15
|
+
$ gem install sf_cli
|
16
|
+
Bundler::
|
17
|
+
in Gemfile:
|
18
|
+
gem 'sf_cli'
|
19
|
+
then,
|
20
|
+
$ bundle install
|
21
|
+
== Documents
|
22
|
+
Class Library Reference::
|
23
|
+
{Online document}[https://www.rubydoc.info/gems/sf_cli/0.0.7] at rubygems.org
|
24
|
+
|
25
|
+
Or,
|
26
|
+
Generate locally:
|
27
|
+
$ git clone https://github.com/tmkw/sf_cli.git
|
28
|
+
$ cd sf_cli
|
29
|
+
$ bundle install
|
30
|
+
$ bundle exec rake rdoc
|
31
|
+
*As* *of* *0.0.7*, *this* *may* *be* *better* *to* *know* *what* *it* *is* *exactly*.
|
32
|
+
Salesforce CLI and Sf command::
|
33
|
+
1. {Salesforce CLI reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_top.htm]
|
34
|
+
2. {sf command reference}[https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm]
|
35
|
+
|
36
|
+
== Short Examples
|
37
|
+
require 'sf_cli'
|
38
|
+
|
39
|
+
# login to org
|
40
|
+
sf.org.login_web
|
41
|
+
|
42
|
+
# get salesforce object schema
|
43
|
+
sf.sobject.describe :Account
|
44
|
+
|
45
|
+
# get a record
|
46
|
+
sf.data.get_record :Account, record_id: 'xxxxxxx'
|
47
|
+
sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
48
|
+
|
49
|
+
# execute soql
|
50
|
+
sf.data.query "SELECT Id, Name FROM Account LIMIT 1" # => [{Id: "abc", Name: "account name"}]
|
51
|
+
|
52
|
+
# create a record
|
53
|
+
sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
|
54
|
+
|
55
|
+
# update a record
|
56
|
+
sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
|
57
|
+
sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
|
58
|
+
|
59
|
+
# delete a record
|
60
|
+
sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
|
61
|
+
sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
|
62
|
+
|
63
|
+
# using Bulk API 2.0
|
64
|
+
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', timeout: 5 # waiting for 5 minutes at maximum
|
65
|
+
|
66
|
+
# run Apex
|
67
|
+
sf.apex.run file: 'path/to/file'
|
68
|
+
sf.apex.run file: StringIO.new("System.debug('Hello World')")
|
69
|
+
== \Object Model Support
|
70
|
+
As of now, there is experimental support for object model in Salesforce.
|
71
|
+
=== Short examples
|
72
|
+
===== With sf command:
|
73
|
+
rows = sf.data.query "SELECT Id, Name FROM Contact WHERE Name = 'Akin Kristen'", model_class: Contact
|
74
|
+
rows.first # <Contact: @Id="0035j00001RW3xbAAD", @Name="Akin Kristen">
|
75
|
+
rows.first.Name # Akin Kristen
|
76
|
+
===== Doing the same thing with model independently
|
77
|
+
contact = Contact.select(:Id, :Name).where(Name: 'Akin Kristen').take
|
78
|
+
contact.Name # Akin Kristen
|
79
|
+
For more details, take a look at {the object model section}[link://files/rdoc/ObjectModel_rdoc.html]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7
|
4
|
+
version: 0.0.7
|
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-09-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a class library for introducing Salesforce CLI to Ruby scripting.
|
14
14
|
Currenty only sf command is the target of development.
|
@@ -16,12 +16,14 @@ email:
|
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files:
|
19
|
-
-
|
19
|
+
- rdoc/ObjectModel.rdoc
|
20
|
+
- rdoc/README.rdoc
|
20
21
|
- CHANGELOG.md
|
21
22
|
files:
|
22
23
|
- CHANGELOG.md
|
23
|
-
- README.rdoc
|
24
24
|
- lib/sf_cli.rb
|
25
|
+
- lib/sf_cli/sf/apex/core.rb
|
26
|
+
- lib/sf_cli/sf/apex/run.rb
|
25
27
|
- lib/sf_cli/sf/console.rb
|
26
28
|
- lib/sf_cli/sf/core/base.rb
|
27
29
|
- lib/sf_cli/sf/data/bulk_result_v2.rb
|
@@ -55,6 +57,8 @@ files:
|
|
55
57
|
- lib/sf_cli/sf/project/core.rb
|
56
58
|
- lib/sf_cli/sf/sobject/core.rb
|
57
59
|
- lib/sf_cli/sf/sobject/schema.rb
|
60
|
+
- rdoc/ObjectModel.rdoc
|
61
|
+
- rdoc/README.rdoc
|
58
62
|
homepage: https://github.com/tmkw/sf_cli
|
59
63
|
licenses:
|
60
64
|
- MIT
|