G4t 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/g4t +2 -2
  3. data/lib/g4t.rb +249 -252
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5987fcbc6ee6dccf87c591bf40001b17f2c75a69baea76a92ad083fe3bbb01ef
4
- data.tar.gz: 6aaea7514763c842f14cb4efa4504d717eae30b071c2c72ca417c43ad979c9d4
3
+ metadata.gz: 12071d7efb40562adf27b9085f76a9b39518051cffe8c4d5474c8535e0d39239
4
+ data.tar.gz: efc7c982c40fd67c732a2d5fa0f0346b06399c426544c92ae0f4d2921645f7af
5
5
  SHA512:
6
- metadata.gz: e1781ddfda3d078abcf66d6249a6de7b99851d0ad3322921fe5730543f18a54b43dee16537361bb2be66b744dac3e7af003f653f8df1887586f4a60f3a74e7d6
7
- data.tar.gz: a0a5875defce772ea407bc9fb1d9d176e233b108413de510afd516ef4cce070fcbeb2d581f49437bd28b6397e059750bd57970bb54e0a8a595c8ab49fb42f1c2
6
+ metadata.gz: 808946461f0318062406a275f61e1c15fa568d8dc15525c581a005f0ee39e77516c2d9436e26cabe3bd30c27d427e370c53207779651f016b1741c28c00ed4d7
7
+ data.tar.gz: fab9e8efe83b793b9902a8205851cfccae5dec41861b9bf629e0f1587e65e2e8271f2c6f388beaebef2abe39fadbb1b31e6f863140d73c7a46572b0a4f126231
data/bin/g4t CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env ruby
2
- require "g4t"
1
+ #!/usr/bin/env ruby
2
+ require "g4t"
data/lib/g4t.rb CHANGED
@@ -1,252 +1,249 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- require "os"
4
- require "tty-prompt"
5
- require "etc"
6
-
7
- module G4t
8
- class Options
9
- def initialize
10
- $prompt = TTY::Prompt.new
11
- end
12
-
13
- def commit_files
14
- $lastmsg = "Now that we commited the files"
15
- msg = $prompt.ask("Commit message:")
16
-
17
- if msg[0] != "\""
18
- msg = "\"#{msg}"
19
- end
20
-
21
- if msg[-1] != "\""
22
- msg = "#{msg}\""
23
- end
24
-
25
- puts msg
26
- run_command("git commit -m #{msg}")
27
- end
28
-
29
- def add_files
30
- $lastmsg = "Now that we added the files"
31
- all_files = $prompt.yes?("Add all files?")
32
- if all_files
33
- cmd = "git add ."
34
- puts("Adding all files...")
35
- else
36
- fname = $prompt.ask("File to add:")
37
- cmd = "git add #{fname}"
38
- end
39
- run_command("#{cmd}")
40
- end
41
-
42
- def logs
43
- run_command("git log")
44
- end
45
-
46
- def push_branch
47
- branch = $prompt.ask("Branch to push:")
48
- run_command("git push origin #{branch}")
49
- end
50
-
51
- def remote_adress
52
- $lastmsg = "Now that we the remote address"
53
- uname = $prompt.ask("Your github username:")
54
- repo = $prompt.ask("Your repository name:")
55
- puts("Adding remote repository https://github.com/#{uname}/#{repo}...")
56
- run_command("git remote add origin https://github.com/#{uname}/#{repo}.git")
57
- end
58
-
59
- def status
60
- run_command("git status")
61
- end
62
-
63
- def clone_repo
64
- uname = $prompt.ask("Username:")
65
- repo = $prompt.ask("Repository name:")
66
- run_command("git clone https://github.com/#{uname}/#{repo}/")
67
- end
68
-
69
- def restore
70
- fname = $prompt.ask("File name:")
71
- run_command("git restore #{fname}")
72
- end
73
-
74
- def reset
75
- commit = $prompt.ask("Commit id:")
76
- run_command("git reset --hard #{commit}")
77
- end
78
-
79
- def hard_reset
80
- confirmation = $prompt.yes?("do you really want to hard reset?")
81
-
82
- if confirmation
83
- run_command("git reset --hard HEAD~")
84
- else
85
- puts "Cancelling operation"
86
- end
87
-
88
- end
89
-
90
- def initialize_git
91
- $lastmsg = "Now that we initialized .git"
92
- puts("Initializing Git repository in '#{Dir.pwd}/.git'...")
93
- run_command("git init")
94
- end
95
-
96
- def diff
97
- run_command("git diff")
98
- end
99
-
100
- def change_branch
101
- bname = $prompt.ask("Branch name:")
102
- run_command("git checkout -b #{bname}")
103
- end
104
-
105
- def git_info
106
- status = {
107
- "Git branch" => IO.popen("git branch"),
108
- "Repository url" => IO.popen("git config --get remote.origin.url")
109
- }
110
- status.each do |k, v|
111
- puts("#{k}: #{v.read}")
112
- end
113
- puts("____________\n\n")
114
- end
115
-
116
- def remove_file
117
- file_name = $prompt.ask("Enter the file name: ")
118
- run_command("git rm #{file_name}")
119
- end
120
-
121
- def show_last_commit
122
- run_command("git show")
123
- end
124
-
125
- def pull_changes
126
- git_pull_options = ["rebase", "no-rebase", "ff-only"]
127
- chose = $prompt.select("chose: ", git_pull_options)
128
- run_command("git pull --#{chose}")
129
- end
130
-
131
- def run_command(cmd)
132
- puts "Command: #{cmd}"
133
- system(cmd)
134
- end
135
- end
136
-
137
- class Run
138
- def initialize
139
- @opt = Options.new
140
- git_init?
141
- start
142
- end
143
-
144
- def verify_system
145
- if OS.windows?; "C:\\Users\\#{Etc.getlogin}\\.gitconfig" else "/home/#{Etc.getlogin}/.gitconfig" end
146
- end
147
-
148
- def git_init?
149
- identify_user
150
- unless File.directory?(".git")
151
- begin
152
- options = ["Clone a repo", "Initialize a repo", "Close"]
153
- @git_init_select = $prompt.select("The .git directory was not found, what do you want to do?", options)
154
- git_init_verify
155
- rescue TTY::Reader::InputInterrupt
156
- abort("\nCloseed")
157
- end
158
- end
159
- end
160
-
161
- def git_init_verify
162
- case @giti_init_select
163
- when "Clone a repo"
164
- @opt.clone_repo
165
- when "Init a repo"
166
- @opt.init_repo
167
- else
168
- abort("It is not possible to continue without a .git repository or cloned repository!")
169
- end
170
- end
171
-
172
- def identify_user
173
- if(File.exist?(verify_system)) == false
174
- begin
175
- email = $prompt.ask("Github email: ")
176
- uname = $prompt.ask("Github username: ")
177
- self.run("git config --global user.email #{email} && git config --global user.name #{uname}")
178
- rescue TTY::Reader::InputInterrupt
179
- abort("\nYou closed the application")
180
- end
181
- end
182
- end
183
-
184
- def show_panel
185
- options = ["Add remote address",
186
- "Add files",
187
- "Commit files",
188
- "Push files to branch",
189
- "Show git status",
190
- "Show git logs",
191
- "Show the last commit",
192
- "Remove a file",
193
- "Show diff",
194
- "Change branch",
195
- "Git pull changes",
196
- "Restore a file",
197
- "Reset to a commit",
198
- "Reset to the last commit",
199
- "Close"
200
- ]
201
-
202
- begin
203
- @opt.git_info
204
- @opt_select = $prompt.select("Select: ", options)
205
- verify_option
206
- rescue TTY::Reader::InputInterrupt
207
- abort("\nYou has closed the application.")
208
- end
209
- end
210
-
211
- def verify_option
212
- case @opt_select
213
- when "Add remote address" then
214
- @opt.remote_adress
215
- when "Add files" then
216
- @opt.add_files
217
- when "Commit files" then
218
- @opt.commit_files
219
- when "Push files to branch" then
220
- @opt.push_branch
221
- when "Show git status" then
222
- @opt.status
223
- when "Show git logs" then
224
- @opt.logs
225
- when "Show diff" then
226
- @opt.diff
227
- when "Restore a file" then
228
- @opt.restore
229
- when "Reset to a commit" then
230
- @opt.reset
231
- when "Reset to the last commit" then
232
- @opt.hard_reset
233
- when "Change branch" then
234
- @opt.change_branch
235
- when "Remove a file" then
236
- @opt.remove_file
237
- when "Show the last commit" then
238
- @opt.show_last_commit
239
- when "Git pull changes" then
240
- @opt.pull_changes
241
- else
242
- abort("Goodbye, closed.")
243
- end
244
- end
245
-
246
- def start
247
- loop { show_panel }
248
- end
249
- end
250
-
251
- Run.new
252
- end
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require "os"
4
+ require "tty-prompt"
5
+ require "etc"
6
+
7
+ module G4t
8
+ class Options
9
+ def initialize
10
+ $prompt = TTY::Prompt.new
11
+ end
12
+ def commit_files
13
+ $lastmsg = "Now that we commited the files"
14
+ msg = $prompt.ask("Commit message:")
15
+
16
+ if msg[0] != "\""
17
+ msg = "\"#{msg}"
18
+ end
19
+
20
+ if msg[-1] != "\""
21
+ msg = "#{msg}\""
22
+ end
23
+
24
+ puts msg
25
+ run_command("git commit -m #{msg}")
26
+ end
27
+
28
+ def add_files
29
+ $lastmsg = "Now that we added the files"
30
+ all_files = $prompt.yes?("Add all files?")
31
+ if all_files
32
+ cmd = "git add ."
33
+ puts("Adding all files...")
34
+ else
35
+ fname = $prompt.ask("File to add:")
36
+ cmd = "git add #{fname}"
37
+ end
38
+ run_command(cmd)
39
+ end
40
+
41
+ def logs
42
+ run_command("git log")
43
+ end
44
+
45
+ def push_branch
46
+ branch = $prompt.ask("Branch to push:")
47
+ run_command("git push origin #{branch}")
48
+ end
49
+
50
+ def remote_adress
51
+ $lastmsg = "Now that we the remote address"
52
+ uname = $prompt.ask("Your github username:")
53
+ repo = $prompt.ask("Your repository name:")
54
+ puts("Adding remote repository https://github.com/#{uname}/#{repo}...")
55
+ run_command("git remote add origin https://github.com/#{uname}/#{repo}.git")
56
+ end
57
+
58
+ def status
59
+ run_command("git status")
60
+ end
61
+
62
+ def clone_repo
63
+ uname = $prompt.ask("Username:")
64
+ repo = $prompt.ask("Repository name:")
65
+ run_command("git clone https://github.com/#{uname}/#{repo}/")
66
+ end
67
+
68
+ def restore
69
+ fname = $prompt.ask("File name:")
70
+ run_command("git restore #{fname}")
71
+ end
72
+
73
+ def reset
74
+ commit = $prompt.ask("Commit id:")
75
+ run_command("git reset --hard #{commit}")
76
+ end
77
+
78
+ def hard_reset
79
+ confirmation = $prompt.yes?("do you really want to hard reset?")
80
+
81
+ if confirmation
82
+ run_command("git reset --hard HEAD~")
83
+ else
84
+ puts "Cancelling operation"
85
+ end
86
+
87
+ end
88
+
89
+ def initialize_git
90
+ $lastmsg = "Now that we initialized .git"
91
+ puts("Initializing Git repository in '#{Dir.pwd}/.git'...")
92
+ run_command("git init")
93
+ end
94
+
95
+ def diff
96
+ run_command("git diff")
97
+ end
98
+
99
+ def change_branch
100
+ bname = $prompt.ask("Branch name:")
101
+ run_command("git checkout -b #{bname}")
102
+ end
103
+
104
+ def git_info
105
+ status = {
106
+ "Git branch" => IO.popen("git branch"),
107
+ "Repository url" => IO.popen("git config --get remote.origin.url")
108
+ }
109
+ status.each do |k, v|
110
+ puts("#{k}: #{v.read}")
111
+ end
112
+ puts("____________\n\n")
113
+ end
114
+
115
+ def remove_file
116
+ file_name = $prompt.ask("Enter the file name: ")
117
+ run_command("git rm #{file_name}")
118
+ end
119
+
120
+ def show_last_commit
121
+ run_command("git show")
122
+ end
123
+
124
+ def pull_changes
125
+ git_pull_options = ["rebase", "no-rebase", "ff-only"]
126
+ chose = $prompt.select("chose: ", git_pull_options)
127
+ run_command("git pull --#{chose}")
128
+ end
129
+
130
+ def run_command(cmd)
131
+ puts "Command: #{cmd}"
132
+ system(cmd)
133
+ end
134
+ end
135
+
136
+ class Run
137
+ def initialize
138
+ @opt = Options.new
139
+ git_init?
140
+ start
141
+ end
142
+
143
+ def verify_system
144
+ if OS.windows?; "C:\\Users\\#{Etc.getlogin}\\.gitconfig" else "/home/#{Etc.getlogin}/.gitconfig" end
145
+ end
146
+ def git_init?
147
+ identify_user
148
+ unless File.directory?(".git")
149
+ begin
150
+ options = ["Clone a repo", "Initialize a repo", "Close"]
151
+ @git_init_select = $prompt.select("The .git directory was not found, what do you want to do?", options)
152
+ git_init_verify
153
+ rescue TTY::Reader::InputInterrupt
154
+ abort("\nCloseed")
155
+ end
156
+ end
157
+ end
158
+
159
+ def git_init_verify
160
+ case @giti_init_select
161
+ when "Clone a repo"
162
+ @opt.clone_repo
163
+ when "Init a repo"
164
+ @opt.init_repo
165
+ else
166
+ abort("It is not possible to continue without a .git repository or cloned repository!")
167
+ end
168
+ end
169
+
170
+ def identify_user
171
+ if(File.exist?(verify_system)) == false
172
+ begin
173
+ email = $prompt.ask("Github email: ")
174
+ uname = $prompt.ask("Github username: ")
175
+ @opt.run_command("git config --global user.email #{email} && git config --global user.name #{uname}")
176
+ rescue TTY::Reader::InputInterrupt
177
+ abort("\nYou closed the application")
178
+ end
179
+ end
180
+ end
181
+
182
+ def show_panel
183
+ options = ["Add remote address",
184
+ "Add files",
185
+ "Commit files",
186
+ "Push files to branch",
187
+ "Show git status",
188
+ "Show git logs",
189
+ "Show the last commit",
190
+ "Remove a file",
191
+ "Show diff",
192
+ "Change branch",
193
+ "Git pull changes",
194
+ "Restore a file",
195
+ "Reset to a commit",
196
+ "Reset to the last commit",
197
+ "Close"
198
+ ]
199
+
200
+ begin
201
+ @opt.git_info
202
+ @opt_select = $prompt.select("Select: ", options)
203
+ verify_option
204
+ rescue TTY::Reader::InputInterrupt
205
+ abort("\nYou has closed the application.")
206
+ end
207
+ end
208
+ def verify_option
209
+ case @opt_select
210
+ when "Add remote address" then
211
+ @opt.remote_adress
212
+ when "Add files" then
213
+ @opt.add_files
214
+ when "Commit files" then
215
+ @opt.commit_files
216
+ when "Push files to branch" then
217
+ @opt.push_branch
218
+ when "Show git status" then
219
+ @opt.status
220
+ when "Show git logs" then
221
+ @opt.logs
222
+ when "Show diff" then
223
+ @opt.diff
224
+ when "Restore a file" then
225
+ @opt.restore
226
+ when "Reset to a commit" then
227
+ @opt.reset
228
+ when "Reset to the last commit" then
229
+ @opt.hard_reset
230
+ when "Change branch" then
231
+ @opt.change_branch
232
+ when "Remove a file" then
233
+ @opt.remove_file
234
+ when "Show the last commit" then
235
+ @opt.show_last_commit
236
+ when "Git pull changes" then
237
+ @opt.pull_changes
238
+ else
239
+ abort("Goodbye, closed.")
240
+ end
241
+ end
242
+
243
+ def start
244
+ loop { show_panel }
245
+ end
246
+ end
247
+
248
+ Run.new
249
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: G4t
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - freazesss