dtk-client 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.license_header +15 -0
  4. data/LICENSE +202 -0
  5. data/README.md +25 -2
  6. data/Rakefile +17 -1
  7. data/bin/dtk +18 -1
  8. data/lib/cli/command/account/add_ssh_key.rb +40 -0
  9. data/lib/cli/command/account/delete_ssh_key.rb +43 -0
  10. data/lib/cli/command/account/list_ssh_keys.rb +31 -0
  11. data/lib/cli/command/account/register_catalog_user.rb +31 -0
  12. data/lib/cli/command/account/set_catalog_credentials.rb +31 -0
  13. data/lib/cli/command/account/set_password.rb +31 -0
  14. data/lib/cli/command/account.rb +31 -0
  15. data/lib/cli/command/mixin.rb +1 -1
  16. data/lib/cli/command/module/delete_from_remote.rb +36 -0
  17. data/lib/cli/command/module/install.rb +15 -5
  18. data/lib/cli/command/module/publish.rb +34 -0
  19. data/lib/cli/command/module/pull_dtkn.rb +35 -0
  20. data/lib/cli/command/module/push_dtkn.rb +34 -0
  21. data/lib/cli/command/module/stage.rb +1 -1
  22. data/lib/cli/command/module/uninstall.rb +13 -7
  23. data/lib/cli/command/module.rb +14 -1
  24. data/lib/cli/command/options.rb +2 -0
  25. data/lib/cli/command/service/converge.rb +1 -1
  26. data/lib/cli/command/service/delete.rb +1 -1
  27. data/lib/cli/command/service/exec.rb +5 -2
  28. data/lib/cli/command/service/exec_sync.rb +4 -1
  29. data/lib/cli/command/service/{list_dependent_modules.rb → list_dependencies.rb} +3 -3
  30. data/lib/cli/command/service/uninstall.rb +11 -4
  31. data/lib/cli/command/service.rb +1 -1
  32. data/lib/cli/command/token.rb +3 -0
  33. data/lib/cli/command.rb +1 -1
  34. data/lib/cli/context/attributes.rb +1 -1
  35. data/lib/cli/context/type/account.rb +42 -0
  36. data/lib/cli/context/type/module.rb +2 -1
  37. data/lib/cli/context/type/service.rb +2 -1
  38. data/lib/cli/context.rb +82 -12
  39. data/lib/cli/version.rb +18 -2
  40. data/lib/client/git_repo/adapter/git_gem.rb +62 -4
  41. data/lib/client/git_repo.rb +33 -2
  42. data/lib/client/load_source/component_info.rb +44 -0
  43. data/lib/client/load_source/service_info.rb +47 -0
  44. data/lib/client/load_source.rb +148 -0
  45. data/lib/client/{util/module_ref.rb → module_ref.rb} +19 -0
  46. data/lib/client/operation/account/add_ssh_key.rb +47 -0
  47. data/lib/client/operation/account/delete_ssh_key.rb +41 -0
  48. data/lib/client/operation/account/list_ssh_keys.rb +28 -0
  49. data/lib/client/operation/account/register_catalog_user.rb +49 -0
  50. data/lib/client/operation/account/set_catalog_credentials.rb +32 -0
  51. data/lib/client/operation/account/set_password.rb +59 -0
  52. data/lib/client/operation/account.rb +7 -4
  53. data/lib/client/operation/client_module_dir/git_repo/internal/dtkn.rb +83 -0
  54. data/lib/client/operation/client_module_dir/git_repo/internal.rb +328 -0
  55. data/lib/client/operation/client_module_dir/git_repo.rb +73 -249
  56. data/lib/client/operation/client_module_dir.rb +2 -2
  57. data/lib/client/operation/module/clone_module.rb +41 -25
  58. data/lib/client/operation/module/delete_from_remote.rb +79 -0
  59. data/lib/client/operation/module/install/common_module.rb +10 -21
  60. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/cache.rb +47 -0
  61. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/resolve_modules.rb +69 -0
  62. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree.rb +143 -0
  63. data/lib/client/operation/module/install/dependent_modules/component_module.rb +103 -0
  64. data/lib/client/operation/module/install/dependent_modules/prompt_helper.rb +54 -0
  65. data/lib/client/operation/module/install/dependent_modules.rb +65 -0
  66. data/lib/client/operation/module/install/mixin.rb +42 -0
  67. data/lib/client/operation/module/install/module_ref.rb +48 -0
  68. data/lib/client/operation/module/install/print_helper.rb +129 -0
  69. data/lib/client/operation/module/install.rb +68 -25
  70. data/lib/client/operation/module/install_from_catalog.rb +23 -32
  71. data/lib/client/operation/module/list.rb +4 -1
  72. data/lib/client/operation/module/publish.rb +78 -0
  73. data/lib/client/operation/module/pull_dtkn.rb +76 -0
  74. data/lib/client/operation/module/push.rb +16 -2
  75. data/lib/client/operation/module/push_dtkn/convert_source/component_info.rb +42 -0
  76. data/lib/client/operation/module/push_dtkn/convert_source/service_info.rb +47 -0
  77. data/lib/client/operation/module/push_dtkn/convert_source.rb +155 -0
  78. data/lib/client/operation/module/push_dtkn.rb +79 -0
  79. data/lib/client/operation/module/stage.rb +3 -2
  80. data/lib/client/operation/module/uninstall.rb +36 -0
  81. data/lib/client/operation/module.rb +23 -4
  82. data/lib/client/operation/service/converge.rb +3 -2
  83. data/lib/client/operation/service/delete.rb +2 -1
  84. data/lib/client/operation/service/destroy.rb +1 -1
  85. data/lib/client/operation/service/exec.rb +4 -0
  86. data/lib/client/operation/service/{list_dependent_modules.rb → list_dependencies.rb} +1 -1
  87. data/lib/client/operation/service/stage.rb +1 -1
  88. data/lib/client/operation/service/uninstall.rb +3 -3
  89. data/lib/client/operation/service.rb +1 -1
  90. data/lib/client/service_and_component_info/transform_from/info/component.rb +57 -0
  91. data/lib/client/service_and_component_info/transform_from/info/service.rb +53 -0
  92. data/lib/client/service_and_component_info/transform_from/info.rb +84 -0
  93. data/lib/client/service_and_component_info/transform_from.rb +47 -0
  94. data/lib/client/service_and_component_info/transform_to/info/component.rb +53 -0
  95. data/lib/client/service_and_component_info/transform_to/info/service.rb +49 -0
  96. data/lib/client/service_and_component_info/transform_to/info.rb +111 -0
  97. data/lib/client/service_and_component_info/transform_to.rb +49 -0
  98. data/lib/client/service_and_component_info.rb +26 -0
  99. data/lib/client/util/console.rb +22 -0
  100. data/lib/client/util/interactive_wizard.rb +90 -0
  101. data/lib/client/util.rb +18 -2
  102. data/lib/dtk_client.rb +5 -2
  103. metadata +63 -15
  104. data/lib/client/content_generator.rb +0 -189
  105. data/lib/client/operation/module/install/external_module.rb +0 -205
@@ -0,0 +1,34 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Module
21
+ subcommand_def 'publish' do |c|
22
+ command_body c, 'publish', 'Publish module installed on server to the repo manager' do |sc|
23
+ sc.flag Token.directory_path, :desc => 'Absolute or relative path to module directory containing updates to publish; not need if in the module directory'
24
+ sc.action do |_global_options, options, _args|
25
+ module_ref = module_ref_in_options_or_context(options)
26
+ Operation::Module.publish(:module_ref => module_ref, :directory_path => options[:directory_path])
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Module
21
+ subcommand_def 'pull-dtkn' do |c|
22
+ command_body c, 'pull-dtkn', 'Pull content from repo manager to client module directory and push to server' do |sc|
23
+ sc.flag Token.directory_path, :desc => 'Absolute or relative path to module directory containing content to update; not need if in the module directory'
24
+ sc.action do |_global_options, options, _args|
25
+ module_ref = module_ref_in_options_or_context(options)
26
+ Operation::Module.pull_dtkn(:module_ref => module_ref, :base_dsl_file_obj => @base_dsl_file_obj)
27
+ Operation::Module.push(:module_ref => module_ref, :base_dsl_file_obj => @base_dsl_file_obj, :directory_path => options[:directory_path])
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,34 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Module
21
+ subcommand_def 'push-dtkn' do |c|
22
+ command_body c, 'push-dtkn', 'Push content from client module directory to repo manager' do |sc|
23
+ sc.flag Token.directory_path, :desc => 'Absolute or relative path to module directory containing updates to push; not need if in the module directory'
24
+ sc.action do |_global_options, options, _args|
25
+ module_ref = module_ref_in_options_or_context(options)
26
+ Operation::Module.push_dtkn(:module_ref => module_ref, :base_dsl_file_obj => @base_dsl_file_obj, :directory_path => options[:directory_path])
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
@@ -35,7 +35,7 @@ module DTK::Client
35
35
  version = options[:version] || module_ref.version
36
36
  service_name = options[:service_name]
37
37
  force = options[:f]
38
- directory_path = options[:directory_path]
38
+ directory_path = options[:directory_path] || @base_dsl_file_obj.parent_dir
39
39
 
40
40
  Validation.validate_name(service_name) if service_name
41
41
 
@@ -17,26 +17,32 @@
17
17
  #
18
18
  module DTK::Client
19
19
  module CLI::Command
20
- module Module
20
+ module Module
21
21
  subcommand_def 'uninstall' do |c|
22
22
  c.arg Token::Arg.module_name, :optional => true
23
23
  command_body c, :uninstall, 'Uninstall module from server' do |sc|
24
24
  sc.switch Token.skip_prompt, :desc => 'Skip prompt that checks if user wants to uninstall module from server'
25
25
  sc.flag Token.directory_path
26
26
  sc.flag Token.version
27
+ sc.flag Token.uninstall_name
27
28
  sc.action do |_global_options, options, args|
28
29
  version = options[:version]
29
30
 
30
- module_ref =
31
- if module_name = args[0]
32
- module_ref_in_options_or_context?(:module_ref => module_name, :version => (version || 'master'))
31
+ module_refs_opts = {:ignore_parsing_errors => true}
32
+ if options[:uninstall_name].nil?
33
+ module_ref =
34
+ if module_name = args[0]
35
+ module_ref_in_options_or_context?({:module_ref => module_name, :version => (version || 'master')}, module_refs_opts)
36
+ else
37
+ module_ref_in_options_or_context(options, module_refs_opts)
38
+ end
33
39
  else
34
- module_ref_in_options_or_context(options)
35
- end
40
+ module_name = options["name"]
41
+ end
36
42
 
37
43
  raise Error::Usage, "You can use version only with 'namespace/name' provided" if version && module_name.nil?
38
44
 
39
- Operation::Module.uninstall(:module_ref => module_ref, :skip_prompt => options[:skip_prompt])
45
+ Operation::Module.uninstall(:module_ref => module_ref, :skip_prompt => options[:skip_prompt], :name => options[:uninstall_name], :version => version)
40
46
  end
41
47
  end
42
48
  end
@@ -21,7 +21,20 @@ module DTK::Client
21
21
  module Module
22
22
  include Command::Mixin
23
23
 
24
- ALL_SUBCOMMANDS = ['install', 'list', 'list-assemblies', 'push', 'uninstall', 'clone', 'list-remotes', 'stage']
24
+ ALL_SUBCOMMANDS = [
25
+ 'install',
26
+ 'list',
27
+ 'list-assemblies',
28
+ 'push',
29
+ 'uninstall',
30
+ 'clone',
31
+ 'list-remotes',
32
+ 'push-dtkn',
33
+ 'stage',
34
+ 'pull-dtkn',
35
+ 'publish',
36
+ 'delete-from-remote'
37
+ ]
25
38
  command_def :desc => 'Subcommands for interacting with DTK modules'
26
39
  ALL_SUBCOMMANDS.each { |subcommand| require_relative("module/#{subcommand.gsub(/-/,'_')}") }
27
40
  end
@@ -19,6 +19,8 @@ module DTK::Client
19
19
  module CLI
20
20
  module Command
21
21
  class Options
22
+ attr_reader :opts_hash
23
+
22
24
  def initialize(opts_hash)
23
25
  @opts_hash = opts_hash
24
26
  end
@@ -28,7 +28,7 @@ module DTK::Client; module CLI
28
28
  args = {
29
29
  :service_instance => service_instance,
30
30
  :force => force,
31
- :directory_path => options[:directory_path]
31
+ :module_dir => @base_dsl_file_obj.parent_dir
32
32
  }
33
33
  Operation::Service.converge(args)
34
34
  end
@@ -35,7 +35,7 @@ module DTK::Client; module CLI
35
35
  args = {
36
36
  :service_instance => service_instance,
37
37
  :skip_prompt => options[:skip_prompt],
38
- :directory_path => directory_path,
38
+ :directory_path => directory_path || base_dsl_file_obj.parent_dir,
39
39
  :recursive => recursive,
40
40
  :force => force
41
41
  }
@@ -29,11 +29,14 @@ module DTK::Client
29
29
 
30
30
  action = args[0]
31
31
  action_params = args[1]
32
-
32
+ directory_path = options[:d] || @base_dsl_file_obj.parent_dir
33
+
33
34
  args = {
34
35
  :service_instance => service_instance,
35
36
  :action => action,
36
- :action_params => action_params
37
+ :action_params => action_params,
38
+ :directory_path => directory_path,
39
+ :command => 'exec'
37
40
  }
38
41
 
39
42
  response = Operation::Service.exec(args)
@@ -28,11 +28,14 @@ module DTK::Client
28
28
 
29
29
  action = args[0]
30
30
  action_params = args[1]
31
+ directory_path = options[:d] || @base_dsl_file_obj.parent_dir
31
32
 
32
33
  args = {
33
34
  :service_instance => service_instance,
34
35
  :action => action,
35
- :action_params => action_params
36
+ :action_params => action_params,
37
+ :directory_path => directory_path,
38
+ :command => 'exec-sync'
36
39
  }
37
40
  response = Operation::Service.exec(args)
38
41
 
@@ -18,13 +18,13 @@
18
18
  module DTK::Client; module CLI
19
19
  module Command
20
20
  module Service
21
- subcommand_def 'list-dependent-modules' do |c|
22
- command_body c, 'list-dependent-modules', 'List dependent modules associated with service instance.' do |sc|
21
+ subcommand_def 'list-dependencies' do |c|
22
+ command_body c, 'list-dependencies', 'List dependent modules associated with service instance.' do |sc|
23
23
  sc.flag Token.directory_path, :desc => 'Absolute or relative path to service instance directory containing updates to pull; not need if in the service instance directory'
24
24
 
25
25
  sc.action do |_global_options, options, _args|
26
26
  service_instance = service_instance_in_options_or_context(options)
27
- Operation::Service.list_dependent_modules(:service_instance => service_instance)
27
+ Operation::Service.list_dependencies(:service_instance => service_instance)
28
28
  end
29
29
  end
30
30
  end
@@ -21,27 +21,34 @@ module DTK::Client; module CLI
21
21
  subcommand_def 'uninstall' do |c|
22
22
  command_body c, :uninstall, 'Uninstalls the service instance from the server' do |sc|
23
23
  sc.flag Token.directory_path, :desc => 'Absolute or relative path to service instance directory associated; not needed if executed in service instance directory'
24
+ sc.flag Token.uninstall_name
24
25
  sc.switch Token.skip_prompt, :desc => 'Skip prompt that checks if user wants to delete the service instance'
25
26
  sc.switch Token.purge, :desc => 'Delete the service instance directory on the client'
26
- sc.switch Token.force, :desc => 'Removes service instance with all nodes and modules'
27
+ sc.switch Token.delete, :desc => 'Removes service instance with all nodes and modules'
27
28
  sc.switch Token.recursive, :desc => 'Delete dependent service instances'
28
29
  sc.action do |_global_options, options, args|
29
30
  directory_path = options[:directory_path]
30
31
  purge = options[:purge]
31
- force = options[:force]
32
+ delete = options[:delete]
32
33
  recursive = options[:recursive]
34
+ name = options[:uninstall_name]
33
35
 
34
36
  if purge && (!directory_path || (directory_path == @base_dsl_file_obj.parent_dir?))
35
37
  raise Error::Usage, "If use option '#{option_ref(:purge)}' then need to call from outside directory and use option '#{option_ref(:directory_path)}'"
36
38
  end
37
- service_instance = service_instance_in_options_or_context(options)
39
+
40
+ if name.nil?
41
+ service_instance = service_instance_in_options_or_context(options, :ignore_parsing_errors => true)
42
+ else
43
+ service_instance = name
44
+ end
38
45
 
39
46
  args = {
40
47
  :service_instance => service_instance,
41
48
  :skip_prompt => options[:skip_prompt],
42
49
  :directory_path => directory_path,
43
50
  :purge => purge,
44
- :force => force,
51
+ :delete => delete,
45
52
  :recursive => recursive
46
53
  }
47
54
  Operation::Service.uninstall(args)
@@ -33,7 +33,7 @@ module DTK::Client
33
33
  'list-actions',
34
34
  'list-attributes',
35
35
  'list-component-links',
36
- 'list-dependent-modules',
36
+ 'list-dependencies',
37
37
  'list-components',
38
38
  'list-nodes',
39
39
  'list-violations',
@@ -47,11 +47,13 @@ module DTK::Client
47
47
  :identity_file => Flag.new(:i, 'PATH-TO-PEM', 'Path to pem file'),
48
48
  :mode => Flag.new(:mode, 'MODE', 'Mode'),
49
49
  :namespace => Flag.new(:n, 'NAMESPACE', 'Namespace'),
50
+ :uninstall_name => Flag.new(:name, 'NAME', 'Module name to uninstall'),
50
51
 
51
52
 
52
53
  # switches
53
54
  # Switch constructor args order: key, desc, opts={}
54
55
  :all => Switch.new(:all, 'All'),
56
+ :delete => Switch.new(:delete, 'Delete'),
55
57
  :force => Switch.new(:f, 'Force'),
56
58
  :purge => Switch.new(:purge, 'Purge'),
57
59
  :push => Switch.new(:push, 'Push changes'),
@@ -74,6 +76,7 @@ module DTK::Client
74
76
  :module_name => 'NAMESPACE/MODULE-NAME',
75
77
  :target_directory => 'TARGET-DIRECTORY',
76
78
  :attribute_name => 'ATTRIBUTE-NAME',
79
+ :keypair_name => 'KEYPAIR-NAME',
77
80
  :attribute_value => 'VALUE'
78
81
  }
79
82
 
data/lib/cli/command.rb CHANGED
@@ -23,7 +23,7 @@ module DTK::Client
23
23
  require_relative('command/subcommand')
24
24
  require_relative('command/options')
25
25
  # above must be included before below
26
- ALL_COMMANDS = [:service, :module]
26
+ ALL_COMMANDS = [:service, :module, :account]
27
27
  ALL_COMMANDS.each { |command_name| require_relative("command/#{command_name}") }
28
28
 
29
29
  def self.command_module(command_name)
@@ -39,7 +39,7 @@ module DTK::Client::CLI
39
39
 
40
40
  def value_from_base_dsl_file(key)
41
41
  if @special_keys.has_key?(key)
42
- @special_keys[key] = @context.value_from_base_dsl_file?(key)
42
+ @special_keys[key] = @context.value_from_base_dsl_file?(key)
43
43
  @special_keys[key]
44
44
  else
45
45
  @special_keys[key] = @context.value_from_base_dsl_file?(key)
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client; module CLI
19
+ class Context
20
+ module Type
21
+ class Account < Context
22
+ include Command::Account
23
+ include Command::Service
24
+ include Command::Module
25
+
26
+ COMMAND_DEFS = [:service, :module, :account]
27
+
28
+ def add_command_defs!
29
+ COMMAND_DEFS.each {|cmd| add_command(cmd)}
30
+ end
31
+
32
+ def context_type
33
+ 'service'
34
+ end
35
+
36
+ def allowed_commands_defs
37
+ COMMAND_DEFS.map { |cmd| cmd.to_s }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end; end
@@ -21,8 +21,9 @@ module DTK::Client; module CLI
21
21
  class Module < Context
22
22
  include Command::Module
23
23
  include Command::Service
24
+ include Command::Account
24
25
 
25
- COMMAND_DEFS = [:service, :module]
26
+ COMMAND_DEFS = [:service, :module, :account]
26
27
 
27
28
  def add_command_defs!
28
29
  COMMAND_DEFS.each {|cmd| add_command(cmd)}
@@ -21,8 +21,9 @@ module DTK::Client::CLI
21
21
  class Service < Context
22
22
  include Command::Service
23
23
  include Command::Module
24
+ include Command::Account
24
25
 
25
- COMMAND_DEFS = [:service, :module]
26
+ COMMAND_DEFS = [:service, :module, :account]
26
27
 
27
28
  def add_command_defs!
28
29
  COMMAND_DEFS.each {|cmd| add_command(cmd)}
data/lib/cli/context.rb CHANGED
@@ -31,6 +31,7 @@ module DTK::Client
31
31
  @base_dsl_file_obj = base_dsl_file_obj
32
32
  @command_processor = Processor.default
33
33
  @context_attributes = Attributes.new(self)
34
+ @options = {}
34
35
  add_command_defs_defaults_and_hooks!
35
36
  end
36
37
  private :initialize
@@ -62,20 +63,83 @@ module DTK::Client
62
63
  attr_reader :context_attributes, :base_dsl_file_obj
63
64
 
64
65
  def module_ref_from_base_dsl_file?
65
- parsed_module = base_dsl_file_obj.parse_content(:common_module_summary)
66
- namespace = parsed_module.val(:Namespace)
67
- module_name = parsed_module.val(:ModuleName)
68
- version = parsed_module.val(:ModuleVersion) || 'master'
66
+ parsed_module_hash = parse_module_content_and_create_hash
67
+ namespace = parsed_module_hash[:namespace]
68
+ module_name = parsed_module_hash[:module_name]
69
+ version = parsed_module_hash[:version] || 'master'
70
+
69
71
  if namespace and module_name
70
72
  client_dir_path = base_dsl_file_obj.parent_dir?
71
73
  ModuleRef.new(:namespace => namespace, :module_name => module_name, :version => version, :client_dir_path => client_dir_path)
72
74
  end
73
75
  end
74
76
 
77
+ def parse_module_content_and_create_hash
78
+ parsed_hash = {}
79
+
80
+ begin
81
+ parsed_module = base_dsl_file_obj.parse_content(:common_module_summary)
82
+ parsed_hash = {
83
+ :namespace => parsed_module.val(:Namespace),
84
+ :module_name => parsed_module.val(:ModuleName),
85
+ :version => parsed_module.val(:ModuleVersion)
86
+ }
87
+ rescue Error::Usage => error
88
+ # if there is syntax error in dsl, we still want to get namespace, name, and version
89
+ # will be used in commands like 'dtk module uninstall', ... where we want to uninstall module even if parsing errors in yaml
90
+ if content = @options[:ignore_parsing_errors] && base_dsl_file_obj.content
91
+ ret_module_info_from_raw_content(parsed_hash, content)
92
+ else
93
+ raise error
94
+ end
95
+ end
96
+
97
+ parsed_hash
98
+ end
99
+
100
+ # get namespace, name and version from raw file content and return as parsed_hash
101
+ def ret_module_info_from_raw_content(parsed_hash, content)
102
+ info_found = lambda {|input_hash| (input_hash[:namespace] && input_hash[:module_name] && input_hash[:version]) }
103
+
104
+ content.each_line do |line|
105
+ if line_match = line.match(/(^module:)(.*)/)
106
+ name_found = true
107
+ full_name = line_match[2].strip
108
+ namespace, name = full_name.split('/')
109
+ parsed_hash.merge!(:namespace => namespace, :module_name => name)
110
+ elsif line_match = line.match(/(^version:)(.*)/)
111
+ version_found = true
112
+ parsed_hash.merge!(:version => line_match[2].strip)
113
+ end
114
+
115
+ break if info_found.call(parsed_hash)
116
+ end
117
+ end
118
+
75
119
  def service_instance_from_base_dsl_file?
76
120
  #raise_error_when_missing_context(:service_instance) unless base_dsl_file_obj.file_type == DTK::DSL::FileType::ServiceInstance::DSLFile::Top
77
121
  base_dsl_file_obj.file_type == DTK::DSL::FileType::ServiceInstance::DSLFile::Top
78
- base_dsl_file_obj.parse_content(:service_module_summary).val(:Name)
122
+ parse_conent_and_ret_service_name
123
+ end
124
+
125
+ def parse_conent_and_ret_service_name
126
+ begin
127
+ base_dsl_file_obj.parse_content(:service_module_summary).val(:Name)
128
+ rescue Error::Usage => error
129
+ if content = @options[:ignore_parsing_errors] && base_dsl_file_obj.content
130
+ ret_service_name_from_raw_content(content)
131
+ else
132
+ raise error
133
+ end
134
+ end
135
+ end
136
+
137
+ def ret_service_name_from_raw_content(content)
138
+ content.each_line do |line|
139
+ if line_match = line.match(/(^name:)(.*)/)
140
+ return line_match[2].strip
141
+ end
142
+ end
79
143
  end
80
144
 
81
145
  # opts can have keys
@@ -97,11 +161,14 @@ module DTK::Client
97
161
  ::DTK::DSL::FileType::ServiceInstance::DSLFile::Top
98
162
  ]
99
163
 
100
- def module_ref_in_options_or_context(options)
101
- module_ref_in_options_or_context?(options) || raise_error_when_missing_context(:module_ref, options)
164
+ def module_ref_in_options_or_context(options, module_refs_opts = {})
165
+ module_ref_in_options_or_context?(options, module_refs_opts) || raise_error_when_missing_context(:module_ref, options)
102
166
  end
103
167
 
104
- def module_ref_in_options_or_context?(options)
168
+ def module_ref_in_options_or_context?(options, module_refs_opts = {})
169
+ # using :ignore_parsing_errors to ret namespace, name and version from .yaml file even if there are parsing errors
170
+ @options.merge!(:ignore_parsing_errors => module_refs_opts[:ignore_parsing_errors])
171
+
105
172
  if options[:module_ref]
106
173
  opts = {:namespace_module_name => options[:module_ref]}
107
174
  opts.merge!(:version => options[:version]) if options[:version]
@@ -114,11 +181,14 @@ module DTK::Client
114
181
  end
115
182
  end
116
183
 
117
- def service_instance_in_options_or_context(options)
118
- service_instance_in_options_or_context?(options) || raise_error_when_missing_context(:service_instance, options)
184
+ def service_instance_in_options_or_context(options, service_refs_opts = {})
185
+ service_instance_in_options_or_context?(options, service_refs_opts) || raise_error_when_missing_context(:service_instance, options)
119
186
  end
120
187
 
121
- def service_instance_in_options_or_context?(options)
188
+ def service_instance_in_options_or_context?(options, service_refs_opts = {})
189
+ # using :ignore_parsing_errors to ret namespace, name and version from .yaml file even if there are parsing errors
190
+ @options.merge!(:ignore_parsing_errors => service_refs_opts[:ignore_parsing_errors])
191
+
122
192
  if ret = options[:service_instance]
123
193
  ret
124
194
  else
@@ -163,7 +233,7 @@ module DTK::Client
163
233
  end
164
234
 
165
235
  def command_processor_object_methods
166
- @@command_processor_object_methods ||= Processor::Methods.all
236
+ @@command_processor_object_methods ||= Processor::Methods.all
167
237
  end
168
238
 
169
239
  end
data/lib/cli/version.rb CHANGED
@@ -1,8 +1,24 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
1
18
  module DTK
2
19
  module Client
3
20
  module CLI
4
- VERSION="0.10.2"
21
+ VERSION="0.10.3"
5
22
  end
6
23
  end
7
24
  end
8
-