sf_cli 1.0.0.beta5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0d747d19bb4e6c437c2314d83d2e11e138b8f3e241a43a59556fa7fad0829f6
4
- data.tar.gz: 9474614d2da8a4bf6b7bc297d81d3221b90a13a65dba0727c1aa8067418bf37b
3
+ metadata.gz: 415eb0ebdf5cd6f1ca904271f4e0f15eef2a99342259d46a9eb7dd32b5e59024
4
+ data.tar.gz: 754bca7f1db6ecbd376e49e20f659d8dd9c06185cfe1f19d08b783baf028e744
5
5
  SHA512:
6
- metadata.gz: 951b09d44c48730ddb22fbe60b54b58179a4c5b34d42e2b374f5a68c291c1d5514dc735cd6a7585840cfaec1936d4b9187ab6846472d870142e502ddec1e8368
7
- data.tar.gz: 4636eb0848036329af68fb63aec261e4eee191147d6c4327b4cc6ad4f4d516a8ae3c59239af0d969a0cbdc6ce6d8979e00984f90770167fe37e369bce2b3434c
6
+ metadata.gz: 296de6697a2e850a5971a7c338c508154e6f640a4573be0240dd66cf6485b5209bfd6844c69362a6c9611e6519839825f38e76eabbcc64ea32d1036dbc523b96
7
+ data.tar.gz: ea6ce0fce6cbfae46ffcf54a79c22065ffc97f5bd061e6f761337391dbafb16ee04fe4cd110d77505422820c88b8e11a386ac69f22cd1c00862e5b0884cbd53e
data/README.rdoc CHANGED
@@ -63,3 +63,20 @@ With sf command:
63
63
  Doing the same thing independently:
64
64
  contact = Contact.select(:Id, :Name).where(Name: 'Akin Kristen').take
65
65
  contact.Name # Akin Kristen
66
+ == Developer Console
67
+ Developer console integrates both sf_cli's command methods and object model librry into IRB to make scripting easier in REPL.
68
+
69
+ You can directly use sf_cli's command methods:
70
+ $ sf_cli
71
+ > sf.query "SELECT Id, Name FROM Case", target_org: :your_org
72
+
73
+ Object Model is also available:
74
+ > use :your_org_name
75
+ > gen :Account, :Contact, :User #=> generate 3 Object model classes
76
+ > acc = Account.find_by Name: 'Hoge Fuga'
77
+
78
+ There are some other console commands:
79
+ > query "SELECT Id, Name, ... FROM BazBar__c" # just same as `sf data query` with human readable format
80
+ > apex "System.debug('abc');" # execute Apex code instantly
81
+
82
+ Type *help* to know all console commands
@@ -12,8 +12,6 @@ module SfCli
12
12
  module Commands
13
13
  def use(target_org)
14
14
  org_info = sf.org.display target_org: target_org
15
- #sf.org.login_web target_org: target_org, instance_url: org_info.instance_url unless org_info.connected?
16
-
17
15
  conn = SfCli::Sf::Model::SfCommandConnection.new target_org: target_org, instance_url: org_info.instance_url
18
16
  conn.open unless org_info.connected?
19
17
 
@@ -56,32 +54,42 @@ module SfCli
56
54
  conf.inspect_mode = true
57
55
  end
58
56
 
57
+ def orgs
58
+ conf.inspect_mode = false
59
+ system 'sf org list'
60
+ conf.inspect_mode = true
61
+ end
62
+
59
63
  alias :gen :generate
60
64
  alias :conn :connection
61
65
 
62
- def help(command = nil)
66
+ def help
63
67
  conf.inspect_mode = false
64
68
  puts <<~HELP
65
69
  Available commands:
66
- use --- set current org. If you use your default org, this isn't needed.
70
+ use --- set current org.
67
71
  gen --- generate Object model classes
68
72
  query --- Query by SOQL with human readable format
69
73
  apex --- run Apex code
70
74
  conn --- show current connection setting
75
+ orgs --- show the list of org
71
76
 
72
77
  Syntax:
73
78
  [use]
74
79
  use target-org
75
80
 
76
81
  parameters:
77
- targat-org --- Username or alias of the org you are going to use.
82
+ targat-org --- Username or alias of the org you are going to use. If you are not sure about them, check by `sf org list`.
83
+
84
+ example:
85
+ use :your_org_alias
78
86
 
79
87
  [gen]
80
88
  gen object-name, object-name, ...
81
89
  generate object-name, object-name, ...
82
90
 
83
91
  parameters:
84
- object-name --- Comma separated Names. Symbol or String can be OK. At least 1 object name is required.
92
+ object-name --- Comma separated Names. Symbol or String can be OK. At least 1 object name is required.
85
93
 
86
94
  example:
87
95
  gen :Account, :Contact, :User
@@ -90,13 +98,16 @@ module SfCli
90
98
  query SOQL
91
99
 
92
100
  parameters:
93
- SOQL --- soql
101
+ SOQL --- soql.You must quote it like "SELECT ...."
102
+
103
+ example:
104
+ query "SELECT Id, Name FROM Account LIMIT 3"
94
105
 
95
106
  [apex]
96
107
  apex apex_code
97
108
 
98
109
  parameters:
99
- apex code --- Apex code you want to execute
110
+ apex code --- Apex code you want to execute.You must quote the code.
100
111
 
101
112
  example:
102
113
  apex "System.debug('abc');"
@@ -104,6 +115,9 @@ module SfCli
104
115
  [conn]
105
116
  conn
106
117
  connection
118
+
119
+ [orgs]
120
+ orgs
107
121
  HELP
108
122
  conf.inspect_mode = true
109
123
  end
@@ -2,6 +2,9 @@ require_relative '../core/base'
2
2
  require_relative './login'
3
3
  require_relative './display'
4
4
  require_relative './list'
5
+ require_relative './list_metadata_types'
6
+ require_relative './list_metadata'
7
+ require_relative './list_limits'
5
8
 
6
9
  module SfCli
7
10
  module Sf
@@ -17,6 +20,9 @@ module SfCli
17
20
  include Login
18
21
  include Display
19
22
  include List
23
+ include ListMetadataTypes
24
+ include ListMetadata
25
+ include ListLimits
20
26
  end
21
27
  end
22
28
  end
@@ -8,8 +8,8 @@ module SfCli::Sf::Org
8
8
 
9
9
  #
10
10
  # Returns the org's connection information
11
- # @param target_org [Symbol,String] an alias of paticular org, or username can be used
12
- # @param api_version [Numeric] override the api version used for api requests made by this command
11
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
12
+ # @param api_version [Numeric] override the api version used for api requests made by this command
13
13
  #
14
14
  # @note this function returns the org information including security sensitive things such as access token, username and so on.
15
15
  # @return [ConnectionInfo] the org's connection information
@@ -32,21 +32,21 @@ module SfCli::Sf::Org
32
32
  # List orgs you’ve created or authenticated to
33
33
  #
34
34
  # @note this function returns org information including security sensitive things such as access token, username and so on.
35
- # @return [OrgConfig] the org configulation
35
+ # @return [Array] the org configulations
36
36
  #
37
37
  # @example
38
- # org_config_list = sf.org.list # returns a list of OrgConfig
38
+ # org_configs = sf.org.list # returns a list of OrgConfig
39
39
  #
40
- # org_config.first.accesstoken # returns the access token
41
- # org_config.first.instance_url # returns the org's url
40
+ # org_configs.first.accesstoken # returns the access token
41
+ # org_configs.first.instance_url # returns the org's url
42
42
  #
43
- # org_config.first.conncected? # check the connection status
44
- # org_config.first.devhub? # check if the org is devhub or not
45
- # org_config.first.scratch? # check if the org is scratch or not
46
- # org_config.first.default? # check if the org is default or not
47
- # org_config.first.default_devhub? # check if the org is devhub default or not
43
+ # org_configs.first.conncected? # check the connection status
44
+ # org_configs.first.devhub? # check if the org is devhub or not
45
+ # org_configs.first.scratch? # check if the org is scratch or not
46
+ # org_configs.first.default? # check if the org is default or not
47
+ # org_configs.first.default_devhub? # check if the org is devhub default or not
48
48
  #
49
- # 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]
49
+ # @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_list_unified command reference
50
50
  #
51
51
  def list
52
52
  flags = {
@@ -0,0 +1,56 @@
1
+ module SfCli::Sf::Org
2
+ module ListLimits
3
+ #
4
+ # Returns the metadata types that are enabled for your org.
5
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
6
+ # @param api_version [Numeric] override the api version used for api requests made by this command
7
+ #
8
+ # @return [Limits] the list of limit information
9
+ #
10
+ # @example
11
+ # limits = sf.org.list_limits
12
+ # limits.names #=> ["ActiveScratchOrgs","AnalyticsExternalDataSizeMB", ...]
13
+ # limits.find :ActiveScratchOrgs #=> <Limit: name="ActiveScratchOrgs", remaining=3, max=3>
14
+ #
15
+ # @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_list_limits_unified command reference
16
+ #
17
+ def list_limits(target_org: nil, api_version: nil)
18
+ flags = {
19
+ :"target-org" => target_org,
20
+ :"api-version" => api_version,
21
+ }
22
+ action = __method__.to_s.tr('_', ' ')
23
+ json = exec(action, flags: flags, redirection: :null_stderr)
24
+
25
+ Limits.new(json['result'])
26
+ end
27
+
28
+ Limit = Data.define(:name, :remaining, :max)
29
+
30
+ class Limits
31
+ include Enumerable
32
+
33
+ def initialize(list)
34
+ @list = list.map {|limit| Limit.new(**limit)}
35
+ end
36
+
37
+ def each(&block)
38
+ list.each(&block)
39
+ end
40
+
41
+ def names
42
+ list.map(&:name)
43
+ end
44
+
45
+ def find(name)
46
+ list.find{|m| m.name == name.to_s}
47
+ end
48
+
49
+ private
50
+
51
+ def list
52
+ @list
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,91 @@
1
+ module SfCli::Sf::Org
2
+ module ListMetadata
3
+ #
4
+ # Returns the metadata types that are enabled for your org.
5
+ # @param metadata [Symbol,String] name of metadata type
6
+ # @param folder [Symbol,String] folder associated with the component such as Report, EmailTemplate, Dashboard and Document
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
9
+ # @param output_file [String] pathname of the file in which to write the results
10
+ #
11
+ # @return [MetadataList] the list of metadata, which contains its name, its source file path and so on
12
+ #
13
+ # @example
14
+ # list = sf.org.list_metadata :ApexClass
15
+ # list.names #=> ["CommunitiesLandingController","SiteLoginControllerTest", ...]
16
+ # list.find :MyProfilePageController #=> <Metadata: full_name="MyProfilePageController" ...>
17
+ #
18
+ # @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_list_metadata_unified command reference
19
+ #
20
+ def list_metadata(metadata, folder: nil, target_org: nil, api_version: nil, output_file: nil)
21
+ flags = {
22
+ :"metadata-type" => metadata,
23
+ :"folder" => folder,
24
+ :"target-org" => target_org,
25
+ :"api-version" => api_version,
26
+ :"output-file" => output_file,
27
+ }
28
+ action = __method__.to_s.tr('_', ' ')
29
+ json = exec(action, flags: flags, redirection: :null_stderr)
30
+
31
+ MetadataList.new(json['result'])
32
+ end
33
+
34
+ Metadata = Data.define(
35
+ :created_by_id,
36
+ :created_by_name,
37
+ :created_date,
38
+ :file_name,
39
+ :full_name,
40
+ :id,
41
+ :last_modified_by_id,
42
+ :last_modified_by_name,
43
+ :last_modified_date,
44
+ :manageable_state,
45
+ :type) do
46
+ def name
47
+ full_name
48
+ end
49
+ end
50
+
51
+ class MetadataList
52
+ include Enumerable
53
+
54
+ def initialize(metadata_list)
55
+ @list = metadata_list.map do |m|
56
+ Metadata.new(
57
+ created_by_id: m['createdById'],
58
+ created_by_name: m['createdByName'],
59
+ created_date: m['createdDate'],
60
+ file_name: m['fileName'],
61
+ full_name: m['fullName'],
62
+ id: m['id'],
63
+ last_modified_by_id: m['lastModifiedById'],
64
+ last_modified_by_name: m['lastModifiedByName'],
65
+ last_modified_date: m['lastModifiedDate'],
66
+ manageable_state: m['manageableState'],
67
+ type: m['type']
68
+ )
69
+ end
70
+ end
71
+
72
+ def each(&block)
73
+ list.each(&block)
74
+ end
75
+
76
+ def names
77
+ list.map(&:name)
78
+ end
79
+
80
+ def find(name)
81
+ list.find{|m| m.name == name.to_s}
82
+ end
83
+
84
+ private
85
+
86
+ def list
87
+ @list
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,85 @@
1
+ module SfCli::Sf::Org
2
+ module ListMetadataTypes
3
+ #
4
+ # Returns the metadata types that are enabled for your org.
5
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
6
+ # @param api_version [Numeric] override the api version used for api requests made by this command
7
+ # @param output_file [String] pathname of the file in which to write the results
8
+ #
9
+ # @return [Result] the command's output
10
+ #
11
+ # @example
12
+ # result = sf.org.list_metadata_types target_org: :dev
13
+ # result.metadata_objects.names #=> ["InstalledPackage","CustomLabels", ...]
14
+ #
15
+ # @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_list_metadata-types_unified command reference
16
+ #
17
+ def list_metadata_types(target_org: nil, api_version: nil, output_file: nil)
18
+ flags = {
19
+ :"target-org" => target_org,
20
+ :"api-version" => api_version,
21
+ :"output-file" => output_file,
22
+ }
23
+ action = __method__.to_s.tr('_', '-').sub('-', ' ')
24
+ json = exec(action, flags: flags, redirection: :null_stderr)
25
+
26
+ Result.new(
27
+ metadata_objects: MetadataObjects.new(json['result']['metadataObjects']),
28
+ organization_namespace: json['result']['organizationNamespace'],
29
+ partial_save_allowed: json['result']['partialSaveAllowed'],
30
+ test_required: json['result']['testRequired']
31
+ )
32
+ end
33
+
34
+ MetadataObject = Data.define(:directory_name, :in_folder, :meta_file, :suffix, :xml_name, :child_xml_names) do
35
+ def name
36
+ xml_name
37
+ end
38
+
39
+ def in_folder?
40
+ in_folder
41
+ end
42
+
43
+ def meta_file?
44
+ meta_file
45
+ end
46
+ end
47
+
48
+ Result = Data.define(:metadata_objects, :organization_namespace, :partial_save_allowed, :test_required)
49
+
50
+ class MetadataObjects
51
+ include Enumerable
52
+
53
+ def initialize(metadata_objects)
54
+ @metadata_objects = metadata_objects.map do |mo|
55
+ MetadataObject.new(
56
+ directory_name: mo['directoryName'],
57
+ in_folder: mo['inFolder'],
58
+ meta_file: mo['metaFile'],
59
+ suffix: mo['suffix'],
60
+ xml_name: mo['xmlName'],
61
+ child_xml_names: mo['childXmlNames']
62
+ )
63
+ end
64
+ end
65
+
66
+ def each(&block)
67
+ metadata_objects.each(&block)
68
+ end
69
+
70
+ def names
71
+ metadata_objects.map(&:name)
72
+ end
73
+
74
+ def find(name)
75
+ metadata_objects.find{|mo| mo.name == name.to_s}
76
+ end
77
+
78
+ private
79
+
80
+ def metadata_objects
81
+ @metadata_objects
82
+ end
83
+ end
84
+ end
85
+ end
@@ -21,28 +21,31 @@ module SfCli::Sf::Org
21
21
  exec(action, flags: flags)
22
22
  end
23
23
 
24
+ # @note This method doesn't support user interactive mode, so *SF_ACCESS_TOKEN* environment variable must be set before calling this method.
24
25
  # Login to the org by access token.
25
- # @note This method doesn't support user interactive mode, so *SF_ACCESS_TOKEN* environment variable must be set before call this method.
26
+ #
27
+ # If you don't set *SF_ACCESS_TOKEN* in the code, you have to set it outside of the script:
28
+ #
29
+ # In Unix/mac
30
+ # $ SF_ACCESS_TOKEN='xxxxxxxxxx'
31
+ # $ ruby app_using_sfcli.rb
32
+ # OR
33
+ # $ SF_ACCESS_TOKEN='xxxxxxxxxx' ruby app_using_sfcli.rb
34
+ #
35
+ # In Windows
36
+ # > set SF_ACCESS_TOKEN=xxxxxxxxxx
37
+ # > ruby app_using_sfcli.rb
26
38
  #
27
39
  # @param target_org [Symbol,String] an alias of paticular org, or username can be used
28
40
  # @param instance_url [String] URL of the instance that the org lives on.
29
41
  #
30
42
  # @example
31
- # ENV['SF_ACCESS_TOKEN'] = 'xxxxxxxxxx'
32
- # sf.org.login_access_token instance_url: https://hoge.bar.baz.salesforce.com
33
- #
34
- # How to set env variable outside of Ruby::
35
- # In Unix/mac::
36
- # $ SF_ACCESS_TOKEN='xxxxxxxxxx'
37
- # $ ruby app_using_sfcli.rb
38
- # OR
39
- # $ SF_ACCESS_TOKEN='xxxxxxxxxx' ruby app_using_sfcli.rb
40
- # In Windows::
41
- # $ set SF_ACCESS_TOKEN=xxxxxxxxxx
42
- # $ ruby app_using_sfcli.rb
43
+ # ENV['SF_ACCESS_TOKEN'] = 'xxxxxxxxxx'
44
+ # sf.org.login_access_token instance_url: 'https://hoge.bar.baz.salesforce.com'
43
45
  #
44
46
  # @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_login_access-token_unified command reference
45
47
  #
48
+ #
46
49
  def login_access_token(instance_url:, target_org: nil)
47
50
  flags = {
48
51
  :"instance-url" => instance_url,
@@ -9,6 +9,7 @@ module SfCli
9
9
  #
10
10
  # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm command reference
11
11
  #
12
+ # @private :nodoc: just for developers
12
13
  module Project
13
14
  # @private :nodoc: just for developers
14
15
  class Core
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: 1.0.0.beta5
4
+ version: 1.1.0
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-26 00:00:00.000000000 Z
11
+ date: 2024-09-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A class library for introducing Salesforce CLI to Ruby scripting. Currenty
14
14
  only sf command is the target of development.
@@ -54,6 +54,9 @@ files:
54
54
  - lib/sf_cli/sf/org/core.rb
55
55
  - lib/sf_cli/sf/org/display.rb
56
56
  - lib/sf_cli/sf/org/list.rb
57
+ - lib/sf_cli/sf/org/list_limits.rb
58
+ - lib/sf_cli/sf/org/list_metadata.rb
59
+ - lib/sf_cli/sf/org/list_metadata_types.rb
57
60
  - lib/sf_cli/sf/org/login.rb
58
61
  - lib/sf_cli/sf/project/core.rb
59
62
  - lib/sf_cli/sf/project/generate.rb