Class: Twit::CLI
Overview
Automatically-built command-line interface (using Thor).
Instance Method Summary collapse
-
#discard ⇒ Object
See Repo#discard.
-
#gui ⇒ Object
See GUI.
-
#include(other_branch = nil) ⇒ Object
Deprecated: use git merge instead.
-
#include_into(other_branch = nil) ⇒ Object
Deprecated: use git merge instead.
-
#init ⇒ Object
See init.
-
#list ⇒ Object
See Repo#list and Repo#current_branch.
-
#open(branch = nil) ⇒ Object
See Repo#open.
-
#rewind(amount) ⇒ Object
See Repo#rewind.
-
#save(message = nil) ⇒ Object
See Repo#save.
-
#saveas(branch = nil, message = nil) ⇒ Object
See Repo#saveas.
Instance Method Details
#discard ⇒ Object
See Repo#discard.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/twit/cli.rb', line 136 def discard begin say "All changes since last save will be reverted." if yes? "Would you like to copy the changes in a different branch instead?" oldbranch = Twit.current_branch newbranch = ask "Enter name for the copy branch:" Twit.saveas newbranch Twit.open oldbranch return elsif no? "These changes will be lost forever! Are you sure?" return end Twit.discard rescue Error => e say "Error: #{e.}" end end |
#include(other_branch = nil) ⇒ Object
Deprecated: use git merge instead.
100 101 102 103 |
# File 'lib/twit/cli.rb', line 100 def include other_branch = nil say "This function has been deprecated." say "Use git merge instead!" end |
#include_into(other_branch = nil) ⇒ Object
Deprecated: use git merge instead.
107 108 109 110 |
# File 'lib/twit/cli.rb', line 107 def include_into other_branch = nil say "This function has been deprecated." say "Use git merge instead!" end |
#init ⇒ Object
See init
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/twit/cli.rb', line 13 def init begin if Twit.is_repo? say "You are already in a repository! (Root directory: #{Twit.repo.root})" return end Twit.init rescue Error => e say "Error: #{e.}" end end |
#list ⇒ Object
See Repo#list and Repo#current_branch
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/twit/cli.rb', line 83 def list begin @current = Twit.current_branch @others = Twit.list.reject { |b| b == @current } rescue Error => e say "Error: #{e.}" return end say "Current branch: #{@current}" say "Other branches:" @others.each do |branch| say "- #{branch}" end end |
#open(branch = nil) ⇒ Object
See Repo#open.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/twit/cli.rb', line 68 def open branch = nil while branch.nil? || branch.strip == "" branch = ask "Please enter the name of the branch to open:" end begin Twit.open branch rescue Error => e say "Error: #{e.}" else say "Opened #{branch}." end end |
#rewind(amount) ⇒ Object
See Repo#rewind.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/twit/cli.rb', line 114 def rewind amount begin unless Twit.nothing_to_commit? return if no? "You have unsaved changes to your branch. Proceed?" end say "This branch will be rewound by #{amount} save points." if yes? "Would you like to save a copy of these last #{amount} points?" oldbranch = Twit.current_branch newbranch = ask "Enter name for the copy branch:" Twit.saveas newbranch Twit.open oldbranch elsif no? "These #{amount} changes may be lost forever! Are you sure?" return end Twit.rewind amount.to_i rescue Error => e say "Error: #{e.}" end end |
#save(message = nil) ⇒ Object
See Repo#save.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/twit/cli.rb', line 27 def save = nil begin if Twit.nothing_to_commit? say "No new edits to save" return end while .nil? || .strip == "" = ask "Please supply a message describing your changes:" end Twit.save rescue Error => e say "Error: #{e.}" end end |
#saveas(branch = nil, message = nil) ⇒ Object
See Repo#saveas.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/twit/cli.rb', line 44 def saveas branch = nil, = nil while branch.nil? || branch.strip == "" branch = ask "Please supply the name for your new branch:" end begin if (not Twit.nothing_to_commit?) && .nil? = ask "Please supply a message describing your changes:" end begin Twit.saveas branch, rescue InvalidParameter => e if /already exists/.match e. say "Cannot saveas to existing branch. Try a git merge!" else say "Error: #{e.}" end end rescue Error => e say "Error: #{e.}" end end |