sf_cli 1.1.0 → 1.2.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: 415eb0ebdf5cd6f1ca904271f4e0f15eef2a99342259d46a9eb7dd32b5e59024
4
- data.tar.gz: 754bca7f1db6ecbd376e49e20f659d8dd9c06185cfe1f19d08b783baf028e744
3
+ metadata.gz: e9e80b705227bf6cc0a20eb798294a8179ac417b70ee1720626c34ede61c57f9
4
+ data.tar.gz: a47fae091fde1fa337f11a3265dc27703a14642ad3dc287dfb400f41f3e0fcdb
5
5
  SHA512:
6
- metadata.gz: 296de6697a2e850a5971a7c338c508154e6f640a4573be0240dd66cf6485b5209bfd6844c69362a6c9611e6519839825f38e76eabbcc64ea32d1036dbc523b96
7
- data.tar.gz: ea6ce0fce6cbfae46ffcf54a79c22065ffc97f5bd061e6f761337391dbafb16ee04fe4cd110d77505422820c88b8e11a386ac69f22cd1c00862e5b0884cbd53e
6
+ metadata.gz: c4f31ede06a4efd8e9bf8e257712ffa2f5be05e0b7a06e79d7d5a056671480d06eaaaace79c5b2896ae4037ae53de46620a5337841b8e9c415397c70fffc9f59
7
+ data.tar.gz: 24a8d99be40d9f0df743dbe0839dd25c31c6d3870123f50f2b806d580c588e37578a7d2341c2eb8a73f3003748e8ddc0ef44f7315467a2e8c67841e0b65189c3
data/README.rdoc CHANGED
@@ -67,7 +67,7 @@ Doing the same thing independently:
67
67
  Developer console integrates both sf_cli's command methods and object model librry into IRB to make scripting easier in REPL.
68
68
 
69
69
  You can directly use sf_cli's command methods:
70
- $ sf_cli
70
+ $ sf_cli -i
71
71
  > sf.query "SELECT Id, Name FROM Case", target_org: :your_org
72
72
 
73
73
  Object Model is also available:
@@ -80,3 +80,15 @@ There are some other console commands:
80
80
  > apex "System.debug('abc');" # execute Apex code instantly
81
81
 
82
82
  Type *help* to know all console commands
83
+
84
+ == Utility
85
+ sf_cli command also have other functions. As of 1.2.0, it can generate Salesforce DX project.
86
+
87
+ Create a project directory and files including manifest file
88
+ $ sf_cli -g project YOUR_PROJECT_NAME
89
+
90
+ Same as above, but the manifest file is built based on the org
91
+ $ sf_cli -g project YOUR_PROJECT_NAME -o YOUR_TARGET_ORG
92
+
93
+ Build project and manifest then retreave metadata such as Apex code at once
94
+ $ sf_cli -g project YOUR_PROJECT_NAME -o YOUR_TARGET_ORG -r
data/bin/sf_cli CHANGED
@@ -1,7 +1,35 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rake'
3
+ require 'optparse'
4
+ require 'sf_cli'
5
+ require 'sf_cli/version'
4
6
 
5
- Rake.application.init
6
- Rake.application.define_task(Rake::Task, :default) { system('irb -r sf_cli/console') }
7
- Rake.application.top_level
7
+ def generate_project(project_name, params)
8
+ base_dir = Dir.pwd
9
+ target_org = params[:"target-org"]
10
+ retrieve_source = params[:retrieve]
11
+
12
+ sf.project.generate project_name, manifest: true
13
+
14
+ Dir.chdir project_name
15
+
16
+ sf.project.generate_manifest from_org: target_org, output_dir: 'manifest' if target_org
17
+ sf.project.retrieve_start manifest: 'manifest/package.xml', target_org: target_org if retrieve_source
18
+ ensure
19
+ Dir.chdir base_dir
20
+ end
21
+
22
+ params = {}
23
+ opt = OptionParser.new
24
+ Version = SfCli::VERSION
25
+
26
+ opt.on('-i', '--irb', 'Start irb session that integrates sf_cli and object model library.') { system 'irb -r sf_cli/console' }
27
+ opt.on('-g OBJECT', '--generate', 'Generate OBJECT. As of now, only project is available as OBJECT.')
28
+ opt.on('-o TARGET_ORG', '--target-org', 'Username or alias of the target org. When specified with "-g model", the manifest file is created based on the org')
29
+ opt.on('-r', '--retrieve', 'Retrieve source files.When specified with "-g model", source files is loaded according to the manifest file.')
30
+
31
+ opt.parse!(ARGV, into: params)
32
+
33
+ if params[:generate] == 'project'
34
+ generate_project(ARGV[0], params)
35
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative '../core/base'
2
2
  require_relative './generate'
3
3
  require_relative './generate_manifest'
4
+ require_relative './retrieve_start'
4
5
 
5
6
  module SfCli
6
7
  module Sf
@@ -9,13 +10,13 @@ module SfCli
9
10
  #
10
11
  # @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
12
  #
12
- # @private :nodoc: just for developers
13
13
  module Project
14
14
  # @private :nodoc: just for developers
15
15
  class Core
16
16
  include ::SfCli::Sf::Core::Base
17
17
  include Generate
18
18
  include GenerateManifest
19
+ include RetrieveStart
19
20
  end
20
21
  end
21
22
  end
@@ -1,6 +1,6 @@
1
1
  module SfCli::Sf::Project
2
2
  module Generate
3
- GenerateResult = Struct.new(:output_dir, :files, :raw_output, :warnings)
3
+ Result = Struct.new(:output_dir, :files, :raw_output, :warnings)
4
4
 
5
5
  #
6
6
  # Generate a Salesforce project
@@ -9,7 +9,7 @@ module SfCli::Sf::Project
9
9
  # @param output_dir [String] output directory
10
10
  # @param manifest [Boolian] switch to create manifest file in the project directory (manifest/package.xml)
11
11
  #
12
- # @return [GenerateResult] the retsult of project generation
12
+ # @return [Result] the retsult of project generation
13
13
  #
14
14
  # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_generate_unified command reference
15
15
  #
@@ -24,7 +24,7 @@ module SfCli::Sf::Project
24
24
  }
25
25
  json = exec(__method__, flags: flags, switches: switches, redirection: :null_stderr)
26
26
 
27
- GenerateResult.new(
27
+ Result.new(
28
28
  output_dir: json['result']['outputDir'],
29
29
  files: json['result']['created'],
30
30
  raw_output: json['result']['rawOutput'],
@@ -0,0 +1,92 @@
1
+ module SfCli::Sf::Project
2
+ module RetrieveStart
3
+ Result = Data.define(:done, :file_properties, :id, :status, :success, :messages, :files) do
4
+ def success?
5
+ success
6
+ end
7
+ end
8
+ FileProperty = Data.define(:created_by_id, :created_by_name, :created_date, :file_name, :full_name, :id,
9
+ :last_modified_by_id, :last_modified_by_name, :last_modified_date, :manageable_state, :type)
10
+ RetrievedFile = Data.define(:full_name, :type, :state, :file_path)
11
+
12
+ # Retrieve metadata from an org to your local project.
13
+ # @param manifest [String] path of the manifest file(package.xml) that specifies the components to retrieve
14
+ # @param metadata [Array] metadata names that specifies the components to retrieve
15
+ # @param source_dir [String] file or directory path to retrieve from the org.
16
+ # @param package_name [Array] package names to retrieve
17
+ # @param target_org [Symbol,String] an alias of paticular org, or username can be used
18
+ # @param output_dir [String] directory root for the retrieved source files
19
+ # @param api_version [Numeric] override the api version used for api requests made by this command
20
+ # @param wait [Integer] number of minutes to wait for command to complete
21
+ # @param ignore_conflicts [Boolean] ignore conflicts and retrieve and save files to your local filesystem
22
+ # @param single_package [Boolean] indicates that the zip file points to a directory structure for a single package
23
+ # @param unzip [Boolian] number of minutes to wait for command to complete
24
+ # @param target_metadata_dir [String] indicates that the zip file points to a directory structure for a single package
25
+ # @param zip_file_name [String] file name to use for the retrieved zip file
26
+ #
27
+ # @return [Result] the retsult of the command
28
+ #
29
+ # @see https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm#cli_reference_project_retrieve_start_unified command reference
30
+ #
31
+ def retrieve_start(metadata: nil, manifest: nil, source_dir: nil, package_name: nil, target_org: nil, output_dir: nil,
32
+ api_version: nil, wait: nil, target_metadata_dir: nil, zip_file_name: nil, ignore_conflicts: false, single_package: false, unzip: false)
33
+
34
+ flags = {
35
+ :manifest => manifest,
36
+ :metadata => metadata&.join(' '),
37
+ :"source-dir" => source_dir,
38
+ :"package-name" => package_name&.join(' '),
39
+ :"target-org" => target_org,
40
+ :"output-dir" => output_dir,
41
+ :"api-version" => api_version,
42
+ :"wait" => wait,
43
+ :"target-metadata-dir" => target_metadata_dir,
44
+ :"zip-file-name" => zip_file_name,
45
+ }
46
+ switches = {
47
+ :"ignore-conflicts" => ignore_conflicts,
48
+ :"single-package" => single_package,
49
+ :"unzip" => unzip,
50
+ }
51
+ action = __method__.to_s.tr('_', ' ')
52
+ json = exec(action, flags: flags, switches: switches, redirection: :null_stderr)
53
+
54
+ Result.new(
55
+ done: json['result']['done'],
56
+ file_properties: json['result']['fileProperties'].map{|fp| create_file_property(fp)},
57
+ id: json['result']['id'],
58
+ status: json['result']['status'],
59
+ success: json['result']['success'],
60
+ messages: json['result']['messages'],
61
+ files: json['result']['files'].map{|f| create_retrieved_file(f)}
62
+ )
63
+ end
64
+
65
+ private
66
+
67
+ def create_file_property(hash)
68
+ FileProperty.new(
69
+ created_by_id: hash['createdById'],
70
+ created_by_name: hash['createdByName'],
71
+ created_date: hash['createdDate'],
72
+ file_name: hash['fileName'],
73
+ full_name: hash['fullName'],
74
+ id: hash['id'],
75
+ last_modified_by_id: hash['lastModifiedById'],
76
+ last_modified_by_name: hash['lastModifiedByName'],
77
+ last_modified_date: hash['lastModifiedDate'],
78
+ manageable_state: hash['manageableState'],
79
+ type: hash['type']
80
+ )
81
+ end
82
+
83
+ def create_retrieved_file(hash)
84
+ RetrievedFile.new(
85
+ full_name: hash['fullName'],
86
+ type: hash['type'],
87
+ state: hash['state'],
88
+ file_path: hash['filePath']
89
+ )
90
+ end
91
+ end
92
+ end
@@ -395,8 +395,18 @@ module SfCli
395
395
  field["permissionable"]
396
396
  end
397
397
 
398
+ PicklistValue = Data.define(:active, :default_value, :label, :valid_for, :value)
399
+
398
400
  def picklist_values
399
- field["picklistValues"]
401
+ field["picklistValues"].map do |value|
402
+ PicklistValue.new(
403
+ active: value['active'],
404
+ default_value: value['defaultValue'],
405
+ label: value['label'],
406
+ valid_for: value['validFor'],
407
+ value: value['value'],
408
+ )
409
+ end
400
410
  end
401
411
 
402
412
  def polymorphic_foreign_key?
@@ -0,0 +1,3 @@
1
+ module SfCli
2
+ VERSION = '1.2.0'
3
+ end
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.1.0
4
+ version: 1.2.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-29 00:00:00.000000000 Z
11
+ date: 2024-10-01 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.
@@ -61,10 +61,12 @@ files:
61
61
  - lib/sf_cli/sf/project/core.rb
62
62
  - lib/sf_cli/sf/project/generate.rb
63
63
  - lib/sf_cli/sf/project/generate_manifest.rb
64
+ - lib/sf_cli/sf/project/retrieve_start.rb
64
65
  - lib/sf_cli/sf/sobject/core.rb
65
66
  - lib/sf_cli/sf/sobject/describe.rb
66
67
  - lib/sf_cli/sf/sobject/list.rb
67
68
  - lib/sf_cli/sf/sobject/schema.rb
69
+ - lib/sf_cli/version.rb
68
70
  homepage: https://github.com/tmkw/sf_cli
69
71
  licenses:
70
72
  - MIT