Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
38 lines (35 loc) · 1.31 KB

File metadata and controls

38 lines (35 loc) · 1.31 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# This class provides the functionality we want. You only need to look at
# this if you want to know how this works. It only needs to be defined
# once, no need to muck around with its internals.
class switch(object):
def __init__(self, value):
self.value = value
self.fall = False
def __iter__(self):
"""Return the match method once, then stop"""
yield self.match
raise StopIteration
def match(self, *args):
"""Indicate whether or not to enter a case suite"""
if self.fall or not args:
return True
elif self.value in args: # changed for v1.5, see below
self.fall = True
return True
else:
return False
if __name__ == "__main__":
action = "check"
for case in switch(action):
if case('check'):
print('-------------Now doing in action: {0}'.format(action))
break
if case('update'):
print('-------------Now doing in action: {0}'.format(action))
break
if case('deploy'):
print('-------------Now doing in action: {0}'.format(action))
break
if case():
print('-------------Unsupport action, check your action: {0}'.format(action))
# No need to break here, it'll stop anyway
Morty Proxy This is a proxified and sanitized view of the page, visit original site.