Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.rb
More file actions
Latest commit
147 lines (126 loc) · 2.82 KB
/
Copy pathcli.rb
File metadata and controls
147 lines (126 loc) · 2.82 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
require_relative'settings'
require_relative'os'
require_relative'git_info'
require_relative'email_formatter'
require_relative'sanitizer'
# User interface and what opens the mailto link
classCLI
defself.run
cli=new(
Settings.default_allowed,
Settings.default_special,
Settings.default_target_branch_is_master,
false
)
cli.check_if_windows
cli.check_if_in_git_repo
cli.check_if_in_master
cli.debug_output
cli.open_mailto_link
end
definitialize(
default_allowed,
default_special,
default_target_branch_is_master,
debug
)
@default_allowed=default_allowed
@default_special=default_special
@default_target_branch_is_master=default_target_branch_is_master
@debug=debug
end
attr_reader:default_allowed,:default_special,
:default_target_branch_is_master,:debug
defcheck_if_windows
ifOS.windows?
$stderr.puts'Script does not support Windows.'
exit1
end
end
defcheck_if_in_git_repo
unlessGitInfo.currently_in_git_repo?
$stderr.puts'Not in a git repository.'
exit1
end
end
defcheck_if_in_master
ifGitInfo.master?
$stderr.puts"You're currently in the 'master' branch."
$stderr.puts"You can't make a deploy request for this branch."
exit1
end
end
defdebug_output
returnunlessdebug
$stdout.puts(<<-OUTPUT.gsub(/^ +/,'')
TO:
---
#{email.to}
SUBJECT:
--------
#{email.subject}
BODY:
-----
#{email.body}
OUTPUT
)
end
defopen_mailto_link
mailto_link="mailto:#{escape(email.to)}?"\
"subject=#{escape(email.subject)}"\
"&body=#{escape(email.body)}"
`#{command} "#{mailto_link}"`
end
private
defescape(text)
Sanitizer.escape(text)
end
defspecial?
yes_no_prompt(
'Does the deployer need any special instructions?',
default_special
)
end
deftarget_branch_is_master?
yes_no_prompt(
"Is 'master' the target branch?",
default_target_branch_is_master
)
end
defyes_no_prompt(question,default_value)
print"#{question}#{yes_no_letters(default_value)} "
loopdo
answer= $stdin.gets.chomp.upcase
ifdefault_allowed && answer == ''
returndefault_value
elsifanswer == 'Y'
returntrue
elsifanswer == 'N'
returnfalse
else
print"Please try again... #{yes_no_letters(default_value)} "
end
end
end
defyes_no_letters(default)
ifdefault_allowed
ifdefault
'[Y/n]'
else
'[y/N]'
end
else
'[Y/N]'
end
end
defemail
@email ||= EmailFormatter.new(special?,target_branch_is_master?)
end
defcommand
ifOS.linux?
'xdg-open'
else
'open'
end
end
end