Module: DTK::Client::EditMixin

Includes:
CloneMixin, PullCloneChangesMixin, PushCloneChangesMixin, ReparseMixin
Included in:
ModuleMixin
Defined in:
lib/commands/common/thor/edit.rb

Constant Summary

Constants included from ReparseMixin

ReparseMixin::YamlDTKMetaFiles

Constants included from CommandHelperMixin

CommandHelperMixin::Loaded

Instance Method Summary collapse

Methods included from ReparseMixin

#reparse_aux

Methods included from PullCloneChangesMixin

#pull_clone_changes?

Methods included from PushCloneChangesMixin

#push_clone_changes_aux

Methods included from CloneMixin

#clone_aux, #clone_base_aux, #create_context_for_module

Methods included from Console

confirmation_prompt, confirmation_prompt_additional_options, confirmation_prompt_multiple_choice, confirmation_prompt_simple, unix_shell, wait_animation

Methods included from CommandHelperMixin

#Helper

Methods included from CommandBase

#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args

Instance Method Details

#attributes_editor(yaml_input) ⇒ Object

returns text string with edited yaml content



130
131
132
133
134
135
136
137
138
139
# File 'lib/commands/common/thor/edit.rb', line 130

def attributes_editor(yaml_input)
  dtk_folder = OsUtil.dtk_local_folder
  file_path = "#{dtk_folder}/temp_attrs.yaml"
  File.open(file_path, 'w'){|f| f << yaml_input}
  OsUtil.edit(file_path)
  OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
  edited_yaml = File.open(file_path,'r'){|f|f.read}
  File.unlink(file_path)
  edited_yaml
end

#edit_aux(module_type, module_id, module_name, version, opts = {}) ⇒ Object

module_type: will be one of :component_module :service_module



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/commands/common/thor/edit.rb', line 36

def edit_aux(module_type,module_id,module_name,version,opts={})
  module_location  = OsUtil.module_location(module_type,module_name,version,opts)

  pull_if_needed = opts[:pull_if_needed]
  # check if there is repository cloned
  unless File.directory?(module_location)
    if opts[:automatically_clone] or Console.confirmation_prompt("Edit not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
      internal_trigger = true
      omit_output = true
      response = clone_aux(module_type,module_id,version,internal_trigger,omit_output,opts)
      # if error return
      return response unless response.ok?
      pull_if_needed = false
    else
      # user choose not to clone needed module
      return
    end
  end
  # here we should have desired module cloned

  if pull_if_needed
    response = pull_clone_changes?(module_type,module_id,version,opts)
    return response unless response.ok?
  end
  grit_adapter = Helper(:git_repo).create(module_location)
  if edit_info = opts[:edit_file]
    #TODO: cleanup so dont need :base_file_name
    file_to_edit =
      if edit_info.kind_of?(String)
        edit_info
      else #edit_info.kind_of?(Hash) and has key :base_file_name
        base_file = edit_info[:base_file_name]
        (File.exists?("#{module_location}/#{base_file}.yaml") ? "#{base_file}.yaml" : "#{base_file}.json")
      end
    OsUtil.edit("#{module_location}/#{file_to_edit}")
    OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
  else
    Console.unix_shell(module_location, module_id, module_type, version)
  end

  unless grit_adapter.repo_exists?
    puts "Local module has been removed, skipping changes."
    return Response::Ok.new()
  end

  unless grit_adapter.changed?
    puts "No changes to repository"
    return Response::Ok.new()
  end

  unless file_to_edit
    grit_adapter.print_status
  end

  # check to see if auto commit flag
  auto_commit  = ::DTK::Configuration.get(:auto_commit_changes)
  confirmed_ok = false

  # if there is no auto commit ask for confirmation
  unless auto_commit
    confirm_msg =
      if file_to_edit
        "Would you like to commit changes to the file?"
      else
        "Would you like to commit ALL the changes?"
      end
    confirmed_ok = Console.confirmation_prompt_simple(confirm_msg)
  end
  if (auto_commit || confirmed_ok)
    if auto_commit
      puts "[NOTICE] You are using auto-commit option, all changes you have made will be commited."
    end
    commit_msg = user_input("Commit message")

    # remove qoutes if they are not closed properly in commit_msg
    commit_msg.gsub!(/\"/,'') unless commit_msg.count('"') % 2 ==0

    internal_trigger=true
    reparse_aux(module_location)

    # use_impl_id - if edit-component-module which has version use impl_id from assembly--<assembly_name> version of component instance
    opts.merge!(:force_parse => true, :update_from_includes => true, :print_dependencies => true, :use_impl_id => true)
    response = push_clone_changes_aux(module_type,module_id,version,commit_msg,internal_trigger,opts)

    # if error return
    return response unless response.ok?
  end

  #TODO: temporary took out; wil put back in
  #puts "DTK SHELL TIP: Adding the client configuration parameter <config param name>=true will have the client automatically commit each time you exit edit mode" unless auto_commit
  Response::Ok.new()
end