sf_cli 0.0.3 → 0.0.5

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/README.rdoc +30 -8
  4. data/lib/sf_cli/sf/core/base.rb +80 -0
  5. data/lib/sf_cli/sf/data/bulk_result_v2.rb +77 -0
  6. data/lib/sf_cli/sf/data/core.rb +39 -0
  7. data/lib/sf_cli/sf/data/create_record.rb +30 -0
  8. data/lib/sf_cli/sf/data/delete_bulk.rb +47 -0
  9. data/lib/sf_cli/sf/data/delete_record.rb +33 -0
  10. data/lib/sf_cli/sf/data/delete_resume.rb +47 -0
  11. data/lib/sf_cli/sf/data/get_record.rb +42 -0
  12. data/lib/sf_cli/sf/data/helper_methods.rb +47 -0
  13. data/lib/sf_cli/sf/data/query.rb +120 -0
  14. data/lib/sf_cli/sf/data/query_helper.rb +57 -0
  15. data/lib/sf_cli/sf/data/resume.rb +87 -0
  16. data/lib/sf_cli/sf/data/search.rb +50 -0
  17. data/lib/sf_cli/sf/data/update_record.rb +38 -0
  18. data/lib/sf_cli/sf/data/upsert_bulk.rb +50 -0
  19. data/lib/sf_cli/sf/data/upsert_resume.rb +47 -0
  20. data/lib/sf_cli/sf/main.rb +31 -0
  21. data/lib/sf_cli/sf/model/class_definition.rb +112 -0
  22. data/lib/sf_cli/sf/model/generator.rb +27 -0
  23. data/lib/sf_cli/sf/model/schema.rb +33 -0
  24. data/lib/sf_cli/sf/model.rb +21 -0
  25. data/lib/sf_cli/sf/org/core.rb +23 -0
  26. data/lib/sf_cli/sf/org/display.rb +41 -0
  27. data/lib/sf_cli/sf/org/list.rb +67 -0
  28. data/lib/sf_cli/sf/org/login.rb +64 -0
  29. data/lib/sf_cli/sf/project/core.rb +83 -0
  30. data/lib/sf_cli/sf/sobject/core.rb +50 -0
  31. data/lib/sf_cli.rb +19 -1
  32. metadata +38 -15
  33. data/lib/sf_cli/sf/base.rb +0 -34
  34. data/lib/sf_cli/sf/data.rb +0 -148
  35. data/lib/sf_cli/sf/org.rb +0 -49
  36. data/lib/sf_cli/sf/project.rb +0 -68
  37. data/lib/sf_cli/sf/sobject.rb +0 -41
  38. data/lib/sf_cli/sf.rb +0 -87
@@ -1,68 +0,0 @@
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
@@ -1,41 +0,0 @@
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 DELETED
@@ -1,87 +0,0 @@
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