Repository navigation
Expand file tree
/
Copy pathflow_commands.py
More file actions
executable file
·154 lines (130 loc) · 4.39 KB
/
Copy pathflow_commands.py
File metadata and controls
executable file
·154 lines (130 loc) · 4.39 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
"""
This file contains all the tasks that can be used to assemble workflows
The config file specifies the task chain that is executed for each transition
"""
import argparse
from gitflow.config.configmanager import ConfigManager
from gitflow.core import GitFlow
class GitFlowCommand(object):
"""
This is just an empty class to serve as the base class for all command line
level sub commands. Since the git-flow loader will auto-detect all
subclasses, implementing a new subcommand is as easy as subclassing the
:class:`GitFlowCommand`.
"""
@classmethod
def register_parser(cls, parent):
"""
This inserts the parameters into the arg parser. If you are creating
a subcommand and want the command to show up when you do git flow help,
enter the code to add it to the parent argument parser here
:param parent:
The parent argument parser
"""
raise NotImplementedError("Implement this method in a subclass.")
@staticmethod
def run(args):
"""
This is the actual logic of the command you are creating. Everything
the command does goes here
:param args:
The arguments passed from the command line to here
"""
raise NotImplementedError("Implement this method in a subclass.")
class GitFlowSimpleTask(object):
"""
This class identifies very simple tasks in the workflow. These would
be akin to one line commands like git add -A and the like
"""
@staticmethod
def run(args):
"""
This is the actual logic of the command you are creating. Everything
the command does goes here
:param args:
The arguments passed from the command line to here
"""
raise NotImplementedError("Implement this method in a subclass.")
class VersionCommand(GitFlowCommand):
"""
This command outside of the workflow system will simply print the version of gitflow plus
"""
@classmethod
def register_parser(cls, parent):
"""
see GitFlowCommand.register_parser comments
:param cls:
:param parent:
:return:
"""
p = parent.add_parser('version', help='Show the version of gitflow.')
p.set_defaults(func=cls.run)
return p
@staticmethod
def run(args):
"""
see GitFlowCommand.run comments
:param args:
:return:
"""
from gitflow import __version__
print(__version__)
class PrintConfigCommand(GitFlowCommand):
"""
This triggers GitFlow to print its configuration to the scren
"""
@classmethod
def register_parser(cls, parent):
"""
see GitFlowCommand.register_parser comments
:param cls:
:param parent:
:return:
"""
p = parent.add_parser('printcfg', help='Print Gitflow Current Config')
p.set_defaults(func=cls.run)
return p
@staticmethod
def run(args):
"""
see GitFlowCommand.run comments
:param args:
:return:
"""
c = ConfigManager(GitFlow())
c.printConfig()
class InitCommand(GitFlowCommand):
"""
This is a hard command outside of the workflow. This initializes the repository
so it can be used with gitflow.
"""
@classmethod
def register_parser(cls, parent):
"""
see GitFlowCommand.register_parser comments
:param cls:
:param parent:
:return:
"""
initMsg = "Initialize a repository for gitflow."
p = parent.add_parser('init', help=initMsg)
# p.add_argument('-f', '--force', action='store_true',
# help='Force reinitialization of the gitflow preferences.')
# p.add_argument('-d', '--defaults', action='store_true',
# dest='use_defaults',
# help='Use default branch naming conventions and prefixes.')
p.set_defaults(func=cls.run)
return p
@staticmethod
def run(args):
"""
see GitFlowCommand.run comments
:param args:
:return:
"""
print('executed InitCommand')
class NotEmpty(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if not values:
raise argparse.ArgumentError(self, 'must not by empty.')
setattr(namespace, self.dest, values)