sf_cli 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c83fc3297315182771f73c3ff599bfdd9abcff1c72a401d69bc8a734e9c7cd17
4
- data.tar.gz: 8ed2425d43258abcc43e7ba9ec0dadf1cc18474d47ea286b38998b564cd68e6d
3
+ metadata.gz: 415eb0ebdf5cd6f1ca904271f4e0f15eef2a99342259d46a9eb7dd32b5e59024
4
+ data.tar.gz: 754bca7f1db6ecbd376e49e20f659d8dd9c06185cfe1f19d08b783baf028e744
5
5
  SHA512:
6
- metadata.gz: f97ab229a3000ac570e2d46ccaf393a6f64fd5717587449dede15c149286624b2b37356f7ef5bbe23772a8e8f14519d291b3addfab0114b5963c5831d7f3d604
7
- data.tar.gz: fb431e461147f16d9a2bac7cf13970f011dc53d77f936dd09a60ed47b2b28259722c3457f435136bfae03673d4bb8df6099ff234852fd03d16c221cf284fe481
6
+ metadata.gz: 296de6697a2e850a5971a7c338c508154e6f640a4573be0240dd66cf6485b5209bfd6844c69362a6c9611e6519839825f38e76eabbcc64ea32d1036dbc523b96
7
+ data.tar.gz: ea6ce0fce6cbfae46ffcf54a79c22065ffc97f5bd061e6f761337391dbafb16ee04fe4cd110d77505422820c88b8e11a386ac69f22cd1c00862e5b0884cbd53e
data/README.rdoc CHANGED
@@ -79,4 +79,4 @@ There are some other console commands:
79
79
  > query "SELECT Id, Name, ... FROM BazBar__c" # just same as `sf data query` with human readable format
80
80
  > apex "System.debug('abc');" # execute Apex code instantly
81
81
 
82
- Type `help` for the help of all console commands
82
+ Type *help* to know all console commands
@@ -54,6 +54,12 @@ module SfCli
54
54
  conf.inspect_mode = true
55
55
  end
56
56
 
57
+ def orgs
58
+ conf.inspect_mode = false
59
+ system 'sf org list'
60
+ conf.inspect_mode = true
61
+ end
62
+
57
63
  alias :gen :generate
58
64
  alias :conn :connection
59
65
 
@@ -66,6 +72,7 @@ module SfCli
66
72
  query --- Query by SOQL with human readable format
67
73
  apex --- run Apex code
68
74
  conn --- show current connection setting
75
+ orgs --- show the list of org
69
76
 
70
77
  Syntax:
71
78
  [use]
@@ -74,6 +81,9 @@ module SfCli
74
81
  parameters:
75
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`.
76
83
 
84
+ example:
85
+ use :your_org_alias
86
+
77
87
  [gen]
78
88
  gen object-name, object-name, ...
79
89
  generate object-name, object-name, ...
@@ -88,13 +98,16 @@ module SfCli
88
98
  query SOQL
89
99
 
90
100
  parameters:
91
- SOQL --- soql
101
+ SOQL --- soql.You must quote it like "SELECT ...."
102
+
103
+ example:
104
+ query "SELECT Id, Name FROM Account LIMIT 3"
92
105
 
93
106
  [apex]
94
107
  apex apex_code
95
108
 
96
109
  parameters:
97
- apex code --- Apex code you want to execute
110
+ apex code --- Apex code you want to execute.You must quote the code.
98
111
 
99
112
  example:
100
113
  apex "System.debug('abc');"
@@ -102,6 +115,9 @@ module SfCli
102
115
  [conn]
103
116
  conn
104
117
  connection
118
+
119
+ [orgs]
120
+ orgs
105
121
  HELP
106
122
  conf.inspect_mode = true
107
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,
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
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