class Twit::CLI

Automatically-built command-line interface (using Thor).

Public Instance Methods

discard() click to toggle source

See {Twit::Repo#discard}.

# 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.message}"
  end
end
gui() click to toggle source

See {Twit::GUI}.

# File lib/twit/cli.rb, line 156
def gui
  Twit::GUI.main
end
include(other_branch = nil) click to toggle source

Deprecated: use git merge instead.

# 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) click to toggle source

Deprecated: use git merge instead.

# 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() click to toggle source

See {Twit::init}

# 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.message}"
  end
end
list() click to toggle source

See {Twit::Repo#list} and {Twit::Repo#current_branch}

# 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.message}"
    return
  end
  say "Current branch: #{@current}"
  say "Other branches:"
  @others.each do |branch|
    say "- #{branch}"
  end
end
open(branch = nil) click to toggle source

See {Twit::Repo#open}.

# 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.message}"
  else
    say "Opened #{branch}."
  end
end
rewind(amount) click to toggle source

See {Twit::Repo#rewind}.

# 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.message}"
  end
end
save(message = nil) click to toggle source

See {Twit::Repo#save}.

# File lib/twit/cli.rb, line 27
def save message = nil
  begin
    if Twit.nothing_to_commit?
      say "No new edits to save"
      return
    end
    while message.nil? || message.strip == ""
      message = ask "Please supply a message describing your changes:"
    end
    Twit.save message
  rescue Error => e
    say "Error: #{e.message}"
  end
end
saveas(branch = nil, message = nil) click to toggle source

See {Twit::Repo#saveas}.

# File lib/twit/cli.rb, line 44
def saveas branch = nil, message = nil
  while branch.nil? || branch.strip == ""
    branch = ask "Please supply the name for your new branch:"
  end
  begin
    if (not Twit.nothing_to_commit?) && message.nil?
      message = ask "Please supply a message describing your changes:"
    end
    begin
      Twit.saveas branch, message
    rescue InvalidParameter => e
      if /already exists/.match e.message
        say "Cannot saveas to existing branch. Try a git merge!"
      else
        say "Error: #{e.message}"
      end
    end
  rescue Error => e
    say "Error: #{e.message}"
  end
end