@@ -240,6 +240,39 @@ def process_cli_args(filters, args):
240240 filters .append (Remap (** dict (zip (topics_from , topics_to ))))
241241
242242
243+ class Copy (RawMessageFilter ):
244+ """Copy topics to other topics."""
245+
246+ def __init__ (self , ** kwargs ):
247+ """
248+ :param dict kwargs: The mapping to use. Keys are topics to be copied, values are their new names.
249+ """
250+ super (Copy , self ).__init__ (include_topics = kwargs .keys ())
251+ self .copy = kwargs
252+
253+ def filter (self , topic , datatype , data , md5sum , pytype , stamp , header ):
254+ return [
255+ (topic , datatype , data , md5sum , pytype , stamp , header ),
256+ (self .copy .get (topic , topic ), datatype , data , md5sum , pytype , stamp , header ),
257+ ]
258+
259+ def _str_params (self ):
260+ return dict_to_str (self .copy , '=>' )
261+
262+ @staticmethod
263+ def add_cli_args (parser ):
264+ parser .add_argument (
265+ '--copy' , nargs = '+' , metavar = "FROM TO" ,
266+ help = "Copy topics. This argument should be an even-sized list of pairs [FROM TO]." )
267+
268+ @staticmethod
269+ def process_cli_args (filters , args ):
270+ if args .remap :
271+ topics_from = args .remap [0 ::2 ]
272+ topics_to = args .remap [1 ::2 ]
273+ filters .append (Copy (** dict (zip (topics_from , topics_to ))))
274+
275+
243276class Throttle (RawMessageFilter ):
244277 """Throttle messages on topics."""
245278
0 commit comments