Class: Options

Inherits:
Object
  • Object
show all
Defined in:
lib/g4tOptions.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



2
3
4
# File 'lib/g4tOptions.rb', line 2

def initialize
  @prompt = TTY::Prompt.new
end

Instance Method Details

#add_filesObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/g4tOptions.rb', line 22

def add_files
  $lastmsg = "Now that we added the files"
  all_files = @prompt.yes?("Add all files?")
  if all_files
    cmd = "git add ."
    puts("Adding all files...")
  else
    fname = @prompt.ask("File to add:")
    cmd = "git add #{fname}"
  end
  run_command(cmd)
end

#change_branchObject



93
94
95
96
# File 'lib/g4tOptions.rb', line 93

def change_branch
  bname = @prompt.ask("Branch name:")
  run_command("git checkout -b #{bname}")
end

#clone_repoObject



56
57
58
59
60
# File 'lib/g4tOptions.rb', line 56

def clone_repo
  uname = @prompt.ask("Username:")
  repo = @prompt.ask("Repository name:")
  run_command("git clone https://github.com/#{uname}/#{repo}/")
end

#commit_filesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/g4tOptions.rb', line 6

def commit_files
  $lastmsg = "Now that we commited the files"
  msg = @prompt.ask("Commit message:")

  if msg[0] != "\""
    msg = "\"#{msg}"
  end

  if msg[-1] != "\""
    msg = "#{msg}\""
  end

  puts msg
  run_command("git commit -m #{msg}")
end

#diffObject



89
90
91
# File 'lib/g4tOptions.rb', line 89

def diff
  run_command("git diff")
end

#git_infoObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/g4tOptions.rb', line 98

def git_info
  status = {
      "Git branch" => IO.popen("git branch"),
      "Repository url" => IO.popen("git config --get remote.origin.url")
  }
  status.each do |k, v|
    puts("#{k}: #{v.read}")
  end
  puts("____________\n\n")
end

#hard_resetObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/g4tOptions.rb', line 72

def hard_reset
  confirmation = @prompt.yes?("do you really want to hard reset?")

  if confirmation
    run_command("git reset --hard HEAD~")
  else
    puts "Cancelling operation"
  end

end

#initialize_gitObject



83
84
85
86
87
# File 'lib/g4tOptions.rb', line 83

def initialize_git
  $lastmsg = "Now that we initialized .git"
  puts("Initializing Git repository in '#{Dir.pwd}/.git'...")
  run_command("git init")
end

#logsObject



35
36
37
# File 'lib/g4tOptions.rb', line 35

def logs
  run_command("git log")
end

#pull_changesObject



118
119
120
121
122
# File 'lib/g4tOptions.rb', line 118

def pull_changes
  git_pull_options = ["rebase", "no-rebase", "ff-only"]
  chose = @prompt.select("chose: ", git_pull_options)
  run_command("git pull --#{chose}")
end

#push_branchObject



39
40
41
42
# File 'lib/g4tOptions.rb', line 39

def push_branch
  branch = @prompt.ask("Branch to push:")
  run_command("git push origin #{branch}")
end

#remote_adressObject



44
45
46
47
48
49
50
# File 'lib/g4tOptions.rb', line 44

def remote_adress
  $lastmsg = "Now that we the remote address"
  uname = @prompt.ask("Your github username:")
  repo = @prompt.ask("Your repository name:")
  puts("Adding remote repository https://github.com/#{uname}/#{repo}...")
  run_command("git remote add origin https://github.com/#{uname}/#{repo}.git")
end

#remove_fileObject



109
110
111
112
# File 'lib/g4tOptions.rb', line 109

def remove_file
  file_name = @prompt.ask("Enter the file name: ")
  run_command("git rm #{file_name}")
end

#resetObject



67
68
69
70
# File 'lib/g4tOptions.rb', line 67

def reset
  commit = @prompt.ask("Commit id:")
  run_command("git reset --hard #{commit}")
end

#restoreObject



62
63
64
65
# File 'lib/g4tOptions.rb', line 62

def restore
  fname = @prompt.ask("File name:")
  run_command("git restore #{fname}")
end

#run_command(cmd) ⇒ Object



124
125
126
127
# File 'lib/g4tOptions.rb', line 124

def run_command(cmd)
  puts "Command: #{cmd}"
  system(cmd)
end

#show_last_commitObject



114
115
116
# File 'lib/g4tOptions.rb', line 114

def show_last_commit
  run_command("git show")
end

#statusObject



52
53
54
# File 'lib/g4tOptions.rb', line 52

def status
  run_command("git status")
end