from lib.Wrappers.ArgumentParser import ArgumentParser
from lib.DockerManagerFactory import DockerManagerFactory


class Pull:
    def __init__(self, manager_factory=None):
        self.manager_factory = manager_factory or DockerManagerFactory()

    def execute(self, *args):
        arguments = self._parse_arguments(*args)
        manager = self.manager_factory.get_manager(arguments.version)
        manager.pull(arguments.components)

    def _parse_arguments(self, command_name, *args):
        parser = ArgumentParser(description='Pulls the desired containers',
                                prog='eyeos ' + command_name)
        parser.add_argument('-v', '--version', metavar='VERSION', type=str,
                            help='pull the version VERSION', default=ArgumentParser.DEFAULT_VERSION)
        # parser.add_argument('-n', '--node', metavar='NODE', type=str, default=['all'], action='append',
        #                     help='pull in NODE only (this flag can be specified multiple times)')
        parser.add_argument('components', metavar='COMPONENT', nargs='*', default=ArgumentParser.DEFAULT_COMPONENTS,
                            help='which component(s) to pull')
        args = parser.parse_args(args)
        return args

import os

from lib.DockerComposeExecutor import DockerComposeExecutor
from lib.Tools import paths


class Pull:
    def __init__(self, manager_factory=None):
        pass

    def execute(self, *args):
        file_path = os.getcwd() + '/environments/compose_files/latest/docker-compose-all.yml'
        docker_compose = DockerComposeExecutor(file_path)
        docker_compose.exec('pull')


Refactor the 'pull' subcommand to use DockerComposeExecutor
Refactor the 'pull' subcommand to use DockerComposeExecutor

The pull subcommand was not working because it depended on an
unimplemented class DockerManagerFactory.

- from lib.Wrappers.ArgumentParser import ArgumentParser
- from lib.DockerManagerFactory import DockerManagerFactory
+ import os
+ 
+ from lib.DockerComposeExecutor import DockerComposeExecutor
+ from lib.Tools import paths
  
  
  class Pull:
      def __init__(self, manager_factory=None):
-         self.manager_factory = manager_factory or DockerManagerFactory()
+         pass
  
      def execute(self, *args):
-         arguments = self._parse_arguments(*args)
-         manager = self.manager_factory.get_manager(arguments.version)
-         manager.pull(arguments.components)
+         file_path = os.getcwd() + '/environments/compose_files/latest/docker-compose-all.yml'
+         docker_compose = DockerComposeExecutor(file_path)
+         docker_compose.exec('pull')
  
-     def _parse_arguments(self, command_name, *args):
-         parser = ArgumentParser(description='Pulls the desired containers',
-                                 prog='eyeos ' + command_name)
-         parser.add_argument('-v', '--version', metavar='VERSION', type=str,
-                             help='pull the version VERSION', default=ArgumentParser.DEFAULT_VERSION)
-         # parser.add_argument('-n', '--node', metavar='NODE', type=str, default=['all'], action='append',
-         #                     help='pull in NODE only (this flag can be specified multiple times)')
-         parser.add_argument('components', metavar='COMPONENT', nargs='*', default=ArgumentParser.DEFAULT_COMPONENTS,
-                             help='which component(s) to pull')
-         args = parser.parse_args(args)
-         return args
  
Refactor the 'pull' subcommand to use DockerComposeExecutor
## Code Before:
from lib.Wrappers.ArgumentParser import ArgumentParser
from lib.DockerManagerFactory import DockerManagerFactory


class Pull:
    def __init__(self, manager_factory=None):
        self.manager_factory = manager_factory or DockerManagerFactory()

    def execute(self, *args):
        arguments = self._parse_arguments(*args)
        manager = self.manager_factory.get_manager(arguments.version)
        manager.pull(arguments.components)

    def _parse_arguments(self, command_name, *args):
        parser = ArgumentParser(description='Pulls the desired containers',
                                prog='eyeos ' + command_name)
        parser.add_argument('-v', '--version', metavar='VERSION', type=str,
                            help='pull the version VERSION', default=ArgumentParser.DEFAULT_VERSION)
        # parser.add_argument('-n', '--node', metavar='NODE', type=str, default=['all'], action='append',
        #                     help='pull in NODE only (this flag can be specified multiple times)')
        parser.add_argument('components', metavar='COMPONENT', nargs='*', default=ArgumentParser.DEFAULT_COMPONENTS,
                            help='which component(s) to pull')
        args = parser.parse_args(args)
        return args

## Instruction:
Refactor the 'pull' subcommand to use DockerComposeExecutor
## Code After:
import os

from lib.DockerComposeExecutor import DockerComposeExecutor
from lib.Tools import paths


class Pull:
    def __init__(self, manager_factory=None):
        pass

    def execute(self, *args):
        file_path = os.getcwd() + '/environments/compose_files/latest/docker-compose-all.yml'
        docker_compose = DockerComposeExecutor(file_path)
        docker_compose.exec('pull')

