-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
executable file
·172 lines (142 loc) · 4 KB
/
Copy pathcode
File metadata and controls
executable file
·172 lines (142 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env ruby
$: << File.join(File.dirname(__FILE__), '..', 'lib') # while this is still in development
require 'gli'
begin # XXX: Remove this begin/rescue before distributing your app
require 'code'
rescue LoadError
STDERR.puts "In development, you need to use `bundle exec bin/code` to run your app"
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
STDERR.puts "Feel free to remove this message from bin/code now"
exit 64
end
require 'code/git'
require 'code/github_api'
require 'code/branch'
require 'code/file_list'
require 'code/system'
include GLI::App
program_desc 'The Coderly Toolbelt'
version Code::VERSION
desc 'Describe some switch here'
switch [:s,:switch]
desc 'Create a new feature branch'
arg_name 'The name of the feature'
command :start do |c|
c.action do |global_options, options, args|
feature_name = args.join('-')
$git.start feature_name
end
end
desc 'Upload your feature branch to GitHub'
command :publish, :pr do |c|
c.switch [:master], desc: 'Make the pull request based off the master branch'
c.action do |global_options, options, args|
$github_api.ensure_authorized
message = args.join(' ')
base_branch = nil
base_branch = Code::Branch.master if options[:master]
current_branch = Code::Branch.current
if (current_branch.has_pull_request?)
Code::System.open_in_browser(current_branch.pull_request_url)
else
$git.publish(base: base_branch, message: message)
end
end
end
desc "Push your current branch"
command :push, :p do |c|
c.action do |global_options, options, branch_name|
$git.push
end
end
desc "Marks the current branch's pr as awaiting review"
command :ready do |c|
c.action do |global_options, options, args|
$github_api.ensure_authorized
Code::Branch.current.mark_prs_as_ready
end
end
desc "Quickly create a pull request from your changes on development."
command :hotfix, :fix do |c|
c.action do |global_options, options, args|
hotfix_name = args.join('-')
$git.hotfix hotfix_name
end
end
desc 'Cleanup after a feature has been merged through GitHub'
command :finish do |c|
c.action do |global_options, options, args|
$git.finish
end
end
desc 'Delete the branch you are working on and switch back to development'
command :cancel do |c|
c.action do |global_options, options, args|
$git.cancel
end
end
desc 'Switch to a branch. You can use sub-commands.'
command :switch, :s do |c|
c.action do |global_options, options, args|
$git.switch(*args)
end
end
desc "Opens the repository search interface on github"
command :search do |c|
c.action do |global_options, options, args|
$git.search
end
end
desc 'Deploy to production'
command :production do |c|
c.action do |global_options, options, args|
end
end
desc 'List all the files in the current directory with the patterns'
command :files do |c|
c.action do |global_options, options, patterns|
puts FileList.new.matching(patterns)
end
end
desc 'Clean up by deleting old branches'
command :clean do |c|
c.action do |global_options, options, patterns|
puts "Deleting local merged branches..."
Code::Branch.merged.each do |branch|
branch.delete!
end
puts "Done!"
puts "Pruning remote branches that don't exist anymore..."
$git.prune_remote_branches
puts "Done!"
end
end
desc 'List the merged branches'
command :merged do |c|
c.action do |global_options, options, patterns|
puts Code::Branch.merged
end
end
desc 'Bundles up the current repo'
command :bundle do |c|
c.action do |global_options, options, args|
bundle_path = $git.bundle
Code::System.reveal(bundle_path)
end
end
pre do |global, command, options, args|
$git = Code::Git.new
$github_api = Code::GitHubAPI.new
true
end
post do |global,command,options,args|
# Post logic here
# Use skips_post before a command to skip this
# block on that command only
end
on_error do |exception|
# Error logic here
# return false to skip default error handling
true
end
exit run(ARGV)