@click.command()<EOL>@click.option(<EOL>'<STR_LIT:-c>',<EOL>'<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>is_flag=True<EOL>)<EOL>@click.option(<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>type=click.STRING<EOL>)<EOL>@click.argument(<EOL>'<STR_LIT:path>',<EOL>type=click.Path(exists=True),<EOL>)<EOL>@click.argument(<EOL>'<STR_LIT:name>',<EOL>type=click.STRING<EOL>)<EOL>@click.pass_context<EOL>def archive(context, clear_log, items, path, name):
history_log = context.obj['<STR_LIT>']<EOL>no_color = context.obj['<STR_LIT>']<EOL>with open(history_log, '<STR_LIT:r>') as f:<EOL><INDENT>history_items = f.readlines()<EOL><DEDENT>if items:<EOL><INDENT>items = [int(item) for item in items.split('<STR_LIT:U+002C>')]<EOL>lines = []<EOL>for index in items:<EOL><INDENT>lines.append(history_items[len(history_items) - index])<EOL><DEDENT>history_items = lines<EOL><DEDENT>with tempfile.TemporaryDirectory() as temp_dir:<EOL><INDENT>for item in history_items:<EOL><INDENT>archive_history_item(item, temp_dir, no_color)<EOL><DEDENT>file_name = '<STR_LIT>'.join([name, '<STR_LIT>'])<EOL>archive_path = os.path.join(path, file_name)<EOL>with tarfile.open(archive_path, "<STR_LIT>") as tar:<EOL><INDENT>tar.add(temp_dir, arcname='<STR_LIT>')<EOL><DEDENT><DEDENT>if clear_log:<EOL><INDENT>if items:<EOL><INDENT>items = list(set(items))<EOL>items.sort()<EOL>for index in items:<EOL><INDENT>context.invoke(delete, item=index)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>context.invoke(clear)<EOL><DEDENT><DEDENT>click.echo(<EOL>'<STR_LIT>'.format(archive_path)<EOL>)<EOL>
Archive the history log and all results/log files.

After archive is created optionally clear the history log.