from libs.spk_v.tkmg import VTask


class SearchTask(VTask):
    def __init__(self, args):
        self.args = args
        super().__init__()
        super().init()
    def run(self, task_manager, app):
        app.repository.make_cache()

        if len(self.args.get('args_l0')) == 0:
            s = "any"
        else:
            s = self.args.get('args_l0')[0]
        sr, usr = app.repository.search(s)

        for b in sr:
            if 'i' in self.args.get('args_l1'):
                print(f'{b.parent_package.repo.id.ljust(10)}:: {b.parent_package.id.ljust(16)} :: {b.tags["version"].ljust(12)} :: {b.id.ljust(16)} :: {str(b.tags["arch"]).ljust(12)} ::  {b.display_name}')

            else:
                print(f'{b.parent_package.repo.id.ljust(10)}:: {b.parent_package.id.ljust(16)} :: {b.tags["version"].ljust(12)} :: {str(b.tags["arch"]).ljust(12)} ::  {b.display_name}')
            if 'v' in self.args.get('args_l1'):
                print(f'{b.tags}')
        super().run(task_manager, app)
