Class: Options
- Inherits:
-
Object
- Object
- Options
- Defined in:
- lib/g4tOptions.rb
Instance Method Summary collapse
- #add_files ⇒ Object
- #change_branch ⇒ Object
- #clone_repo ⇒ Object
- #commit_files ⇒ Object
- #diff ⇒ Object
- #git_info ⇒ Object
- #hard_reset ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #initialize_git ⇒ Object
- #logs ⇒ Object
- #pull_changes ⇒ Object
- #push_branch ⇒ Object
- #remote_adress ⇒ Object
- #remove_file ⇒ Object
- #reset ⇒ Object
- #restore ⇒ Object
- #run_command(cmd) ⇒ Object
- #show_last_commit ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize ⇒ Options
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_files ⇒ Object
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_branch ⇒ Object
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_repo ⇒ Object
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_files ⇒ Object
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 |
#diff ⇒ Object
89 90 91 |
# File 'lib/g4tOptions.rb', line 89 def diff run_command("git diff") end |
#git_info ⇒ Object
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_reset ⇒ Object
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_git ⇒ Object
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 |
#logs ⇒ Object
35 36 37 |
# File 'lib/g4tOptions.rb', line 35 def logs run_command("git log") end |
#pull_changes ⇒ Object
118 119 120 121 122 |
# File 'lib/g4tOptions.rb', line 118 def pull_changes = ["rebase", "no-rebase", "ff-only"] chose = @prompt.select("chose: ", ) run_command("git pull --#{chose}") end |
#push_branch ⇒ Object
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_adress ⇒ Object
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_file ⇒ Object
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 |
#reset ⇒ Object
67 68 69 70 |
# File 'lib/g4tOptions.rb', line 67 def reset commit = @prompt.ask("Commit id:") run_command("git reset --hard #{commit}") end |
#restore ⇒ Object
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_commit ⇒ Object
114 115 116 |
# File 'lib/g4tOptions.rb', line 114 def show_last_commit run_command("git show") end |
#status ⇒ Object
52 53 54 |
# File 'lib/g4tOptions.rb', line 52 def status run_command("git status") end |