@@ -135,18 +135,28 @@ def import_sm(qualname):
135135 return smclass
136136
137137
138- def write_image (qualname , out ):
138+ def write_image (qualname , out , events = None ):
139139 """
140140 Given a `qualname`, that is the fully qualified dotted path to a StateMachine
141141 classes, imports the class and generates a dot graph using the `pydot` lib.
142142 Writes the graph representation to the filename 'out' that will
143143 open/create and truncate such file and write on it a representation of
144144 the graph defined by the statemachine, in the format specified by
145145 the extension contained in the out path (out.ext).
146+
147+ If `events` is provided, the machine is instantiated and each event is sent
148+ before rendering, so the diagram highlights the current active state.
146149 """
147150 smclass = import_sm (qualname )
148151
149- graph = DotGraphMachine (smclass ).get_graph ()
152+ if events :
153+ machine = smclass ()
154+ for event_name in events :
155+ machine .send (event_name )
156+ else :
157+ machine = smclass
158+
159+ graph = DotGraphMachine (machine ).get_graph ()
150160 out_extension = out .rsplit ("." , 1 )[1 ]
151161 graph .write (out , format = out_extension )
152162
@@ -165,6 +175,11 @@ def main(argv=None):
165175 "out" ,
166176 help = "File to generate the image using extension as the output format." ,
167177 )
178+ parser .add_argument (
179+ "--events" ,
180+ nargs = "+" ,
181+ help = "Instantiate the machine and send these events before rendering." ,
182+ )
168183
169184 args = parser .parse_args (argv )
170- write_image (qualname = args .class_path , out = args .out )
185+ write_image (qualname = args .class_path , out = args .out , events = args . events )
0 commit comments