Class: Fact::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/fact/files_cli.rb,
lib/fact/activities_cli.rb

Class Method Summary collapse

Class Method Details

.browse_actifitiesObject

Browse all the undelivered activities in the current stream.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fact/activities_cli.rb', line 16

def Cli.browse_actifities
  cc = ClearCase.new

  activity = Cli.choose_undelivered_activity

  unless activity.nil?
    # Come back every time to showing the files in the activity
    loop do
      file_version = Cli.choose_file_from_activity(activity)
      break if file_version.nil? # The activity doesn't contain any files

      say("Fetching the file description... ")
      version_info = cc.get_version_info(file_version)
      say("Done")

      puts ""
      Cli.show_version_info(version_info)
   
      puts ""
      if version_info[:checkout] != "" and version_info[:checkout] != cc.get_current_view
        say("The file is checked out in a different view. Check it in to diff.")
      elsif agree("Compare with the change set predecessor?")
        say("Graphical diff is being opened in an external application.")
        cc.diff_versions(file_version[:file], file_version[:version], version_info[:changeset_predecessor])
      end
    end
  end

end

.browse_hijackedObject

Shows a list of all the hijacked files and allows to perform various actions on the files.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fact/files_cli.rb', line 16

def Cli.browse_hijacked
  cc = Fact::ClearCase.new

  puts ""
  say("Scanning for hijacked files in <%= color('#{File.absolute_path('.')}', BOLD) %>... ")
  files = cc.get_hijacked_files
  say("Done")

  if files.empty?
    say("No hijacked files.")
  else
    say("The hijacked files in the directory and its subdirectories are:")

    # Show the hijacked files list in a menu
    chosen_hijack = choose do |menu|
      menu.prompt    = "Choose a file: "
      menu.select_by = :index

      files.each do |file|
        menu.choice(file[:file]) { file  }
      end

      # Undo hijack for all the files in one command
      file_names = files.collect {|f| f[:file]}
      menu.choice("Keep the changes and checkout all the files") { cc.checkout_hijacked(file_names); exit(true) }

      # The last entry allows graceful exit
      menu.choice("Exit") { exit(true) }
    end

    Cli.operate_hijacked_file(chosen_hijack[:file], chosen_hijack[:version])

  end
end

.choose_file_from_activity(activity_name) ⇒ Object

Asks to choose from a list of files in the activity and returns the last version of the file in the activity in a hash with keys :file and :version.



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
# File 'lib/fact/activities_cli.rb', line 89

def Cli.choose_file_from_activity(activity_name)

  cc = ClearCase.new

  puts ""
  say("Fetching the change set for the activity <%= color('#{activity_name}', BOLD) %>... ")
  changeset = cc.get_activity_change_set(activity_name)
  say("Done.")

  if changeset.empty?
    say("The changeset is empty.")
  else
    say("The activity contains the following files:")

    # The method will return the choice from the menu
    return choose do |menu|
      menu.prompt    = "Enter the file number: "
      menu.select_by = :index

      #  Add a menu entry for each file in the changeset
      changeset.each do |file, versions|
        # Suffix contains the versions count and the check-out indicator
        suffix = "version#{"s" unless versions.size<2}) #{"<%= color('CHECKED-OUT!', :red) %>" if cc.checkout_version?(versions.last)}"
        menu.choice("#{file} (#{versions.size} #{suffix}") { {:file => file, :version => versions.last} }
      end

      # The last entry allows graceful exit
      menu.choice("Exit") { exit(true) }

    end
  end

end

.choose_undelivered_activityObject

Ask the user to choose from the list of all the undelivered activities in the current stream. Returns the name of the chosen activity.



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
# File 'lib/fact/activities_cli.rb', line 51

def Cli.choose_undelivered_activity

  cc = ClearCase.new

  stream = cc.get_current_stream
  return if stream==""

  puts ""
  say("Fetching the stream activities... ")
  activities = cc.get_activities
  say("Done.")

  if activities.empty?
    say("No undelivered activities.")
  else
    say("These are the undelivered activities in the current stream:")

    return choose do |menu|
      menu.prompt    = "Enter the activity number: "
      menu.select_by = :index

      # Add a menu entry for each activity
      activities.each do |activity|
        menu.choice(activity[:headline]) { activity[:name] }
      end

      # The last entry allows graceful exit
      menu.choice("Exit") { exit(true) }

    end
  end

end

.operate_hijacked_file(file_name, original_version) ⇒ Object

Presents a list of operations that can be performed on a single hijacked file.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fact/files_cli.rb', line 53

def Cli.operate_hijacked_file(file_name, original_version)
  cc = Fact::ClearCase.new

  puts ""
  say("Hijacked file <%= color('#{file_name}', BOLD) %>")
  choose do |menu|
      menu.prompt    = "Enter command number: "
      menu.select_by = :index

      menu.choice("Compare with the latest version") do
        puts ""
        say("Graphical diff is being opened in an external application.")
        cc.diff_vob_version(file_name, original_version)
      end

      menu.choice("Drop the changes and renounce the hijack") { cc.undo_hijack([file_name])       }
      menu.choice("Keep the changes and checkout")            { cc.checkout_hijacked([file_name]) }
      menu.choice("Exit") { exit(true) }
    end
end

.show_version_info(info) ⇒ Object

The parameter must be a hash with the following keys:

:version, :name, :activity, :date, :user,
:versions_count, :changeset_predecessor


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fact/files_cli.rb', line 79

def Cli.show_version_info(info)

  cc = ClearCase.new

  if cc.checkout_version?(info[:version])
    last_ver_text = "<%= color('CHECKED-OUT!', :red) %> in #{info[:checkout]}"
  else
    last_ver_text = "#{info[:version]}"
  end

  # Splitting the path and the name so the name can be shown in bold
  path      = info[:name].scan(/.*\//)[0]
  file_name = info[:name].scan(/\/[^\/]+$/)[0]
  file_name.slice!(0) # Removing the leading slash

  say("#{path}<%= color('#{file_name}', BOLD) %>")
  say("    Last activity:")
  say("        Activity name: #{info[:activity]}")
  say("        Last version:  #{last_ver_text}")
  say("                       created on #{info[:date]} by #{info[:user]}")
  say("                       #{info[:versions_count]-1} more version#{"s" unless info[:versions_count]==2} in the activity")
  say("    Activity predecessor: #{info[:changeset_predecessor]}")
end