Exemple #1
0
 def _list(self):
     parser = argparse.ArgumentParser(
         description='''List all the items of the given context:
 -  directly in the console if no arguments
 -  export in a CSV/JSON file (with --export <filepath>)
 ''')
     parser.add_argument('--export', help='File path for the export')
     args = self.second_parser(parser)
     if args.export:
         if args.export.endswith('.csv'):
             results = self.db._list(table=self.context)
             Factory._export_csv(data=results, filepath=args.export)
         elif args.export.endswith('.json'):
             results = self.db._list(table=self.context)
             Factory._export_json(data=results, filepath=args.export)
     else:
         results = self.db._list(table=self.context)
         for result in results:
             print(result)